MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Evaluation of functions inside Plot

Several people have already been pointed out that your input works after
some typing errors hve been corrected to give

   { Abs[x+y I], Hue[ N[(Pi+Arg[x + y I]) /(2 Pi)]]},

So I shall try to deal with some aspects or the evaluation ol Plot - at
least those concerning the first entry and wrapping Evaluate around it:

Plot has the attributes HoldAll, this lets it evaluate in its own way

Plot[expr, {x, xmin, xmax}] first looks at the form of the *unevaluated*
 if this is not a list, then it tries to find points on the line to be
drawn by successively evaluating expr with  x assigned constructed real
numbera as values; it expects that these evaluations will all give real
numbers but it does its best with what it finds
 if it is a list, then it effectivley flattens this to, say, {e1, e2, ...};
evaluates the Plot[ ei, {x,xmin, xmax}] without showing them ; then  it
shows results together.

1. The following "fails" because, for example, when x =2, Mathematica finds
that D[Sin[2],2] makes no sense.

Plot[D[Sin[x],x], {x,0,7}];

But if D[Sin[x],x] is made to evaluate to Cos[x] before x receives numerical
values, then all is OK

Plot[Evaluate[D[Sin[x], x]], {x, 0, 7}];

2. The following "fails" because, Plot examines the unevaluated expr, finds
that it is not a list, and then  finds no real values for  expr  (for
example, when x = -2.0 , whereas it evalutes to {0, 1.73205]} - not a real

expr = {x,Sqrt[x^2-1]};


But if expr is made to evaluate to {x,Sqrt[x^2-1]} before the form is
checked then Plot finds that it is dealing with a list and behaves as
expected -  but, of course, it cannot plot Sqrt[x^2-1] for x between -1 and


Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Hans-Peter Kunzle" <HP.Kunzle at> wrote in message
news:87tpki$5iq at
> I still do not understand well enough how expressions get
> evaluated inside a Plot or similar functions (NDSolve etc.).
> This time I copied the code directly from the (quite old)
> book by T.W. Gray and J. Glynn, Exploring Mathematics with
> Mathematica (p.142):
> Plot3D[
>   { Abs[x+y I], Hue[ N[(Pi+Arg[x + yI]) /(2 Pi)]]},
>   {x,-2,2},{y,-2,2}],
>   AxesLabel->{"Re","Im","Abs[z]"},PlotPoints->15
> ];
> This produces several error messages
> Plot3D::plnc:
>     {Abs[x + y I], Hue[(N[([Pi] + Arg[x + yI])\(2 Pi)]]} is neither a
>     machine-size real number at {x,y}={-2.,-2.} nor a list of a real
>     and a \alid color directive.
> This book was written for Mathematica 2, of course, and presumably
> the code must have worked then. Has anything changed since then?
> I have tried to wrap 'Evaluate' around some of the expressions, but
> this had no effect. Since Abs and Arg only work for numerical
> arguments I also tried to replace them by explicit expressions in
> x and y. But this did not help either.
> Any help is appreciated.
> Hans
> --
> H.P. Künzle                    | Office: (780)492-3798,492-3396
> Dept. of Mathematical Sciences | Fax:    (780)492-6826
> University of Alberta          | E-mail: HP.Kunzle at
> Edmonton, Canada T6G 2G1 | WWW:

  • Prev by Date: Re: Finding parts of Equations...
  • Next by Date: Sorting
  • Previous by thread: Re: Evaluation of functions inside Plot
  • Next by thread: Re: Removing In and Out Labels in all Open Notebooks