0
$\begingroup$

When plotting, the Mathematica seems to substitute the value of the variable only after evaluating the plotted function. To use a simple example where I'm trying to examine how changing certain parameters affect a model:

randomData = RandomReal[{0, 1}, {10, 2}];
LogLinearPlot[
 LinearModelFit[randomData, x, x, Weights -> (# + q &)][1],
 {q, 1, 5}
 ]

gives lots of errors saying:

LinearModelFit::wtsnn: One or more weight values are not non-negative numbers. Weight values must be non-negative.

This seems to be because (# + q &) is being evaluated before LogLinearPlot substitutes the value of q, and LinearModelFit doesn't like receiving non-numerical weights.

When I use Plot, this can be fixed by putting it into a Module,

(* This works fine *)
Plot[
 Module[{}, LinearModelFit[randomData, x, x, Weights -> (# + q &)][1]],
 {q, 0, 5}
 ]

but this doesn't seem to work with LogLinearPlot for some reason.

How do I make LogLinearPlot substitute the variable before any evaluation has taken place? How do I ensure that the value of q is substituted before (# + q &) is evaluated?

$\endgroup$
  • 1
    $\begingroup$ Your first code runs fine with no errors. Maybe you have some old definitions. Try clearing the variables or quiting the kernel altogether. $\endgroup$ – corey979 Nov 14 '16 at 15:54
  • $\begingroup$ Nope. Tried again in a new notebook after restarting the application, same result. It does give an output though, so maybe it's actually a warning instead of error. But it still slows down the computation noticeably and generates lots of spam messages, so still needs to be fixed. $\endgroup$ – goweon Nov 14 '16 at 17:04
  • 1
    $\begingroup$ I get no error as well with MMA 11.0. What version are you using? $\endgroup$ – anderstood Nov 14 '16 at 18:16
  • $\begingroup$ Hmm... interesting. I'm still on v10.0. I'll try upgrading and see if that fixes it. $\endgroup$ – goweon Nov 14 '16 at 18:23
  • 1
    $\begingroup$ No error on V10.3. $\endgroup$ – anderstood Nov 14 '16 at 20:19
0
$\begingroup$

Seems to be a bug in v10.0 that LogLinearPlot has different behavior from Plot. Problem fixed by upgrading to v11.0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.