MathGroup Archive 1997

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

Search the Archive

FW: Re: Release questi

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9496] FW: [mg9410] Re: [mg9366] Release questi
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Sat, 8 Nov 1997 23:04:28 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

I intended to send this to the mathgroup yeasterday. I think I only sent
it to Alan Hayes, and not the mathgroup.
 ----------------------------------------------

Alan Hayes wrote a very good duscussion of Plot evaluation. His message
included:
 ---------------------------------------------- |
|**** Why have this HoldAll feature? **** Here is  an example in its
|favour (from Cameron Smith & Nancy   Blachman, The Mathematica
Graphics |Guidebook)
|
|In[16]:= h[x_/;x<0]:= -1
|In[17]:= h[x_]:= 1
|In[18]:= Plot[h[x],{x,-1,1}];
|If we force h[x] to evaluate immediately then it becomes simply 1
|In[19]:= Plot[Evaluate[h[x]],{x,-1,1}]; |

I would rather give Plot the HoldRest Attribute using the following 
commands:

In[5]:=  ClearAttributes[Plot, HoldAll];
              SetAttributes[Plot, HoldRest];

Of course this will cause the plot above to come out wrong.  But on the 
other hand all the troublesome examples Alan gave (listed below) work
just  fine without using Evaluate, Release or any other extra steps. 
As Alan  pointed out they produce error messages and no useable
graphics with the  default Plot Attributes.


In[6]:=  f=x^3;
g=-x^3;
Plot[D[f,x],{x,0,1}]

In[7]:=  rl=a->2;
Plot[{f,a g}/.rl,{x,0,1}]

In[8]:=  fg={f,g};
Plot[fg,{x,0,1}]


One point Alan didn't mention is that the next command takes my computer
12.79 Seconds to evaluate when Plot has the HoldAll Attribute.  When
Plot  has HoldRest instead it takes only 1.54  Seconds.

In[9]:=  fun=1/2+Sum[(-1)^n 2 Cos[(2 n+1)Pi t]/((2n+1)Pi),{n,0,20}];
Plot[fun, {t, -1, 3}]//Timing

Note:
If Plot has the HoldAll Attribute you can use Plot[ Evaluate[fun], {t,
-1, 3}]
to produce a plot in about 1.5 Seconds.

     Ted Ersek
     ersek_ted%pax1a at mr.nawcad.navy.mil



  • Prev by Date: RE: Re: Assigning solutions fou
  • Next by Date: Re: Re: Release questi
  • Previous by thread: RE: Re: Assigning solutions fou
  • Next by thread: Re: Re: Release questi