Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}];
TableForm[p, 
  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:

ListPlot[p];

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?

share|improve this question
    
Remove the PaddedForm wrapper: ListPlot[Table[{x, f@x}, {x, -3, 3, .5}]]. –  Öskå May 5 at 18:07
    
@Öskå You reply or Community Wiki or something? :) –  belisarius May 5 at 18:12
    
ahahah, I'm on it! Wiki! –  Öskå May 5 at 18:13

2 Answers 2

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:

ClearAll["`*"]
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

share|improve this answer
1  
+1 CW upvotes are a passport to heaven. –  belisarius May 5 at 18:19
    
That might explain why I can't even upvote my own CW answer :( –  Öskå May 5 at 18:20
    
@Ö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}. –  Alexey Popkov May 5 at 22:40
    
@AlexeyPopkov that's the reason why it's a Community Wiki :) But thanks for the info :) I based my assumptions on that answer. –  Öskå May 5 at 22:56
    
@Ö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. –  Alexey Popkov May 5 at 23:06

With your p

ListPlot[First /@ # & /@ p]

enter image description here

share|improve this answer
    
F.Y.I.: Map[First, p, {2}] replaces the First /@ # /@ p :) –  Öskå May 5 at 23:19
    
@Öskå, Thank you. –  qwerty May 5 at 23:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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