I defined a function f[x_] = x^3 2 x. Then I had to construct a table showing vertically, the values of f corresponding to x on the interval [-3,3] in increment of 0.5.

So, I did this:

f[x_] = x^3 - 2 x;
a := PaddedForm[x, {2, 1}];
b := PaddedForm[f[x], {5, 3}];
p = Table[{a, b}, {x, -3, 3, .5}];
  TableHeadings -> {None,{"x", "f(x)=x^3-2x"}}, 
  TableAlignments -> Center]

I had my answers and so far it was ok. But next, I had to plot the set of values with heavy dots. So I did this:


But now there's an error saying:

Co-ordinate -3.0 in {-3.0,-21.000} is not a floating-point number ....

How do I fix this?

  • $\begingroup$ Remove the PaddedForm wrapper: ListPlot[Table[{x, f@x}, {x, -3, 3, .5}]]. $\endgroup$ – Öskå May 5 '14 at 18:07
  • $\begingroup$ @Öskå You reply or Community Wiki or something? :) $\endgroup$ – Dr. belisarius May 5 '14 at 18:12
  • $\begingroup$ ahahah, I'm on it! Wiki! $\endgroup$ – Öskå May 5 '14 at 18:13

In the PaddedForm documentation you can find:

PaddedForm acts as a "wrapper", which affects printing, but not evaluation.

This means that PaddedForm is just an inert wrapper which does not evaluate to something numeric. ListPlot requires numbers but after wrapping a number with PaddedForm or any other inert wrapper it does not a number anymore. One could check it with NumberQ:

NumberQ /@ {PaddedForm[1, {2, 1}], g[2], Hold[3], 1[4]}
{False, False, False, False}

Of course ListPlot will not display anything when a list containing no numbers is passed to it.

The following will work:

f[x_] := x^3 - 2 x;
ListPlot[Table[{x, f@x}, {x, -3, 3, .5}]]

enter image description here

  • $\begingroup$ That might explain why I can't even upvote my own CW answer :( $\endgroup$ – Öskå May 5 '14 at 18:20
  • $\begingroup$ @Öskå Your interpretation of the Documentation statement is not correct: Plotting in Mathematica generally does not imply displaying or printing anything at all! The reason for the error message is clear: a number wrapped by arbitrary Head is not a number anymore. Instead of PaddedForm there could be any other inert wrapper, for example g or Hold or even a number like this: 1[1]. Try ListPlot[{g[1], Hold[2], 1[1]}] - nothing is displayed because there are no numbers in the list! One could check it with NumberQ: NumberQ /@ {g[1], Hold[2], 1[1]} gives {False, False, False}. $\endgroup$ – Alexey Popkov May 5 '14 at 22:40
  • $\begingroup$ @AlexeyPopkov that's the reason why it's a Community Wiki :) But thanks for the info :) I based my assumptions on that answer. $\endgroup$ – Öskå May 5 '14 at 22:56
  • $\begingroup$ @Öskå That answer is correct and does not contradict me in any sense. One thing that will help you to understand that answer deeper is that now FrontEnd is able to render Graphics directly but before Mathematica 6 FrontEnd was able to render only PostScript and Bitmap graphics and the Kernel converted Graphics to PostScript for the purposes of displaying in the FrontEnd. That complicated things a bit. Also Graphics and "graphics" has different meanings when speaking about Mathematica. $\endgroup$ – Alexey Popkov May 5 '14 at 23:06
  • $\begingroup$ I see. Thanks for the info and for correcting the answer :) $\endgroup$ – Öskå May 5 '14 at 23:18

With your p

ListPlot[First /@ # & /@ p]

enter image description here

  • $\begingroup$ F.Y.I.: Map[First, p, {2}] replaces the First /@ # /@ p :) $\endgroup$ – Öskå May 5 '14 at 23:19
  • $\begingroup$ @Öskå, Thank you. $\endgroup$ – qwerty May 5 '14 at 23:29

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.