MathGroup Archive 2003

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

Search the Archive

Re: Explain this (error in Plot[Evaluate[Range[3]],{x,0,1}])

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41851] Re: [mg41776] Explain this (error in Plot[Evaluate[Range[3]],{x,0,1}])
  • From: Omega Consulting <info at omegaconsultinggroup.com>
  • Date: Sat, 7 Jun 2003 00:08:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

At 06:31 AM 6/5/2003, 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

There are two ways to store a list in Mathematica. Normal lists and packed 
arrays (which are much more memory efficient). Range automatically creates 
a packed array.
In[1]:= Developer`PackedArrayQ[Range[3]]
Out[1]= True

Typed lists are not.
In[2]:= Developer`PackedArrayQ[{1,2,3}]
Out[2]= False

That seems to be the source of the error. Plot doesn't recognize that the 
PackedArray is a list and tries to plot the entire Range as a single value 
(which fails).

If you unpack the array, then Range works.
Plot[Evaluate[Developer`FromPackedArray[Range[3]]], {x, 0, 1}]

While this fails.
Plot[Evaluate[Developer`ToPackedArray[{1, 2, 3}]], {x, 0, 1}]

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com


  • Prev by Date: Re: Taking a function as a parameter of a function
  • Next by Date: Problem using Quotient and Mod functions with rational parameters
  • Previous by thread: Re: Explain this (error in Plot[Evaluate[Range[3]],{x,0,1}])
  • Next by thread: Laplacian and curlcurl with maxwells eqn's