Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: a question about plot a list of functions.

  • To: mathgroup at
  • Subject: [mg58207] Re: [mg58203] a question about plot a list of functions.
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Wed, 22 Jun 2005 03:29:33 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

On 22 Jun 2005, at 14:55, Zhou Jiang wrote:

> *This message was transferred with a trial version of CommuniGate 
> (tm) Pro*
> I defined a function as
> K=(2 r/(1-r^2))^2;
> y=1/(1+K (Sin[x])^2);
> y=y/.{r->{0.2,0.9,0.995}}
> Now the result is a list.
> I want to plot y vs. x in one figure and I did the following
> Plot[y, {x, 0, 10 Pi}];
> But Mathematica gave me an error.
> I changed it to
> Plot[{y[[1]], y[[2]], y[[3]]}, {x, 0, 10 Pi}];
> Mathematica gave me a correct plot. Can anyone give me some idea  
> why the error message is given by Mathematica since y is a list and  
> nothing is diffrent from {y[[1]], y[[2]], y[[3]]}?
> Thanks.

Mathematica uses a different algorithm for plotting a single function  


and for plottign sevral function,a s wiht


Plot has the Attribute HoldAll so it does not evaluate it's  
arguments. So if you are going to plot a list of functions  
Mathematica has to be able to see that the first argument has the  
Head List, otherwise it will try using the wrong algorithm.

In your case you are plotting y, but why is a symbol, not a list. It  
only becomes a List after evaluating. So the following will work fine:

Plot[Evaluate[y], {x, 0, 10 Pi}];

In this case Mathematica first evaluates y, sees that it has Head  
List and then uses the correct algorithm (for plotting multiple  

Your second approach

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

also works because again Mathematica can see the the Head List and  
applies the correct algorithm.

But with

Plot[y, {x, 0, 10 Pi}]

the wrong algorithm (for plotting a single real valued function) is  
used and naturally Mathematica complains that your function values  
are not real numbers (they are actually lists  of real numbers).

Andrzej Kozlowski

Chiba, Japan

  • Prev by Date: Re: a small problem from a newbee...
  • Next by Date: Re: a small problem from a newbee...
  • Previous by thread: a question about plot a list of functions.
  • Next by thread: Re: a question about plot a list of functions.