3
$\begingroup$

I've a problem. I defined a simple list and a function like below:

lst := {5, 10, 20}
f[m_] := lst[[Floor[m/10]]];

and drew a plot

Plot[f[x], {x, 10, 38}]

which works fine. But when calling LogPlot

LogPlot[f[x], {x, 10, 38}]

the following error appears before the plot

Part::pspec: "Part specification Floor[x/10] is neither a machine-sized integer nor a list of machine-sized integers"

Can anyone suggest me what's going on and how to deal with this error?

Thank you in advance!

$\endgroup$
  • 1
    $\begingroup$ I believe this question is a duplicate, specifically the issue of Plot first attempting a symbolic evaluation of the function. Can anyone find it? $\endgroup$ – Mr.Wizard Aug 23 '14 at 3:08
  • $\begingroup$ Yeah I would also like to now if that symbolic manipulation of LogPlot can be turned off somehow, so that I can plot a function without having to specify the function arguments as done in the answer below. $\endgroup$ – Santi Apr 22 '15 at 12:36
3
$\begingroup$

LogPlot[] is trying to symbolically manipulate your f[], and the Part[] function fails at that.

You may try to specify that your function should be evaluated only for numerical input, but not symbolically:

lst := {5, 10, 20}
f[m_?NumericQ] := lst[[Floor[m/10]]];
LogPlot[f[x], {x, 10, 38}]
$\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.