Re: Explain this (error in Plot[Evaluate[Range[3]],{x,0,1}])
- To: mathgroup at smc.vnet.net
- Subject: [mg41813] Re: [mg41776] Explain this (error in Plot[Evaluate[Range[3]],{x,0,1}])
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Fri, 6 Jun 2003 09:50:43 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Actually the problem seems to be fairly deep.
Consider:
In[1]:=
a={1,2,3}
Out[1]=
{1,2,3}
In[2]:=
b=Range[3]
Out[2]=
{1,2,3}
In[3]:=
a===b
Out[3]=
True
So a and b are identical. Yet Plot[Evaluate[a],{x,0,1}] works and
Plot[Evaluate[b],{x,0,1}] doesn't? So where is the difference. Well:
In[4]:=
Developer`PackedArrayQ[a]
Out[4]=
False
In[5]:=
Developer`PackedArrayQ[b]
Out[5]=
True
So, by the famous principle of Sherlock Holmes that when you have
eliminated all other possibilities whatever remains must be the truth,
I believe that the answer must lie in the fact that Plot sees a packed
array as a single object rather than a list of objects. But whether
this is a bug or not is hard to say. I don't think this behaviour was
intended (presumably Plot could unpack any packed arrays that are
passed to it) but it seems to me pretty harmless.
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/
On Thursday, June 5, 2003, at 08:31 pm, Martin wrote:
> I don't get it.
>
> It boils down to plotting multiple lines:
>
> Plot[{1,2,3},{x,0,1}] works.
>
> That Plot[Range[3],{x,0,1}] does not work
> I understand (non-standard evaluation in
> Plot), but what is the problem with
>
> Plot[Evaluate[Range[3]],{x,0,1}] ?
>
> Why does Evaluate not do its job for Range?
> It does work with Table as in
>
> Plot[Evaluate[Table[i,{i,3}]],{x,0,1}]
>
> I changed the Attributes of Range to match
> Table's, that did not fix it.
>
> Some deeper reason or just a bug?
>
> I am using Mathematica 4.0.1, W2k
>
>
>