The Long Answer

If Plot is given a function in its first argument that produces anything be a real number, then you will get an error like the one that is the subject of this question.  For example, it should be obvious why you get a problem here.

Plot[Sqrt[x], {x, -1, 1}]

Plot :: plnr : Sqrt[x] is not a machine-size real number at x = -1. .  More…

Plot :: plnr : Sqrt[x] is not a machine-size real number at x = -0.918866 .  More…

Plot :: plnr : Sqrt[x] is not a machine-size real number at x = -0.830382 .  More…

General :: stop : Further output of  Plot :: plnr will be suppressed during this calculation. More…

[Graphics:../HTMLFiles/faq1_11.gif]

-Graphics -

Here is another example where the error is clear and can't be fixed with Evaluate.  We assume y hasn't been defined, so we clear it here.

Clear[y] ;

Plot[ x + y, {x, 0, 1}]

Plot :: plnr : x + y is not a machine-size real number at x = 4.16667*10^^-8 .  More…

Plot :: plnr : x + y is not a machine-size real number at x = 0.040567 .  More…

Plot :: plnr : x + y is not a machine-size real number at x = 0.0848088 .  More…

General :: stop : Further output of  Plot :: plnr will be suppressed during this calculation. More…

[Graphics:../HTMLFiles/faq1_19.gif]

-Graphics -

However, here is one that we would expect to work.   First we define y as a function of x with an explicit parameter, b.

y[b_] := Sin[b x ]

We can generate a list of expressions in terms of x this way:

Map[y, {1, 2, 3}]

{sin(x), sin(2 x), sin(3 x)}

Generally it is possible to plot lists of functions, so we might try the following, but it generates the same error as above.

Plot[Map[y, {1, 2, 3}], {x, 0, Pi}]

Plot :: plnr : y/@{1, 2, 3} is not a machine-size real number at x = 1.309*10^^-7 .  More…

Plot :: plnr : y/@{1, 2, 3} is not a machine-size real number at x = 0.127445 .  More…

Plot :: plnr : y/@{1, 2, 3} is not a machine-size real number at x = 0.266435 .  More…

General :: stop : Further output of  Plot :: plnr will be suppressed during this calculation. More…

[Graphics:../HTMLFiles/faq1_29.gif]

-Graphics -

The problem is that, for a good reason, the expression Map[y,{1,2,3}] isn't evaluated right away, so when Mathematica tries to substitute a real number for x, it isn't substituted into {sin(x),sin(2 x),sin(3 x)}.   However explicitly telling Mathematica to evaluate the Map expression gives us the desired result.

Plot[Evaluate[Map[y, {1, 2, 3}]], {x, 0, Pi}]

[Graphics:../HTMLFiles/faq1_32.gif]

-Graphics -

Why make things to difficult?  The reason is that an opposite problem will frequently occur if the first argument isn't held.   For example, the following Plot should work as expected, even though we happen to have assigned a value for w.

w = 0.1 ;

Plot[E^w, {w, -1, 1}]

[Graphics:../HTMLFiles/faq1_36.gif]

-Graphics -

If the first argument of Plot is evaluated we get

w = 0.1 ;

Plot[Evaluate[E^w], {w, -1, 1}]

[Graphics:../HTMLFiles/faq1_40.gif]

-Graphics -

So, without the HoldAll attribute, we would have to carefully choose symbols with no value before plotting, which would be just one of the problems that would appear.


Created by Mathematica  (March 2, 2006) Valid XHTML 1.1!