Re: Re: Problem plotting high-order Laguerre polynomials
- To: mathgroup at smc.vnet.net
- Subject: [mg63901] Re: [mg63879] Re: [mg63849] Problem plotting high-order Laguerre polynomials
- From: Hartmut.Wolf at t-systems.com
- Date: Sat, 21 Jan 2006 01:50:47 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
> -----Original Message----- > From: Elinor K. Irish [mailto:eirish at pas.rochester.edu] To: mathgroup at smc.vnet.net > Subject: [mg63901] [mg63879] Re: [mg63849] Problem plotting high-order > Laguerre polynomials > > > I want to say thank you to the people who have replied to my message > already. From the responses I've received, it seems that I need to > clarify the problem a bit further. The function I gave is > the simplest > example I could come up with which illustrates the problem I'm running > into. I am actually trying to plot functions which involve sums over > terms of that form, from n=0 to n=70 or so. Also, the actual > functions > I'm working with are two-dimensional, so I'm doing 3D plots. > > So, my questions are: > 1. Why does using Evaluate on this type of function give > incorrect results? > 2. What is the fastest way to plot it correctly? > > For example, on my machine the command > > Plot[func /. n -> 40, {q, 0, 30}, PlotRange -> All] > > typically takes 0.06 seconds to execute, while the command > > Plot[Evaluate[func /. n -> 40], {q, 0, 30}, PlotRange -> All] > > takes 0.01 seconds. Using the form > > func2[n_][q_] := Exp[-q^2] 1/Pi LaguerreL[n, 2 q^2] > Plot[func2[40][q], {q, 0, 30}, PlotRange -> All] > > as suggested takes 0.05-0.06 seconds, which doesn't really help. > > Let me know if I can clarify this further. > > Thanks, > Elinor > > > Hi folks, > > I'm doing some work which involves plotting fairly > high-order Laguerre > polynomials, up to 200 or so. I've been getting some very strange and > obviously incorrect results which seem to have to do with the order of > evaluation. (I'm using Mathematica 5.0, but I've checked it > in 5.2 and > I > > get the same problems.) Here are some examples with a > simple form of > the > > type of function I'm working with: > > > > func = 1/Pi Exp[- q^2] LaguerreL[n, 2 q^2] > > > > These commands work, displaying the expected oscillatory result: > > > > Plot[func /. n -> 40, {q, 0, 30}, PlotRange -> All] > > Plot[Evaluate[func] /. n -> 40, {q, 0, 30}, PlotRange -> All] > > > > This form, however, results in a big mess which isn't even bounded > correctly: > > > > Plot[Evaluate[func /. n -> 40], {q, 0, 30}, PlotRange -> All] > > > > I don't know whether this is a bug or if there's a subtlety of > > Plot/Evaluate/etc. which I don't understand. I would very > much like to > be > > able to use Evaluate on my functions before plotting them, > because my > actual calculations involve complicated sums over expressions > like that > above and take a LONG time to plot. (With Evaluate, a single > plot takes > about 20 minutes; without it the same plot takes nearly 4 hours.) > > > > Could anyone shed some light on this problem? I have more examples, > including some involving sums, which I can give if needed. I've been > fighting with this issue for a long time... > > > > Thanks, > > Elinor > > > > > > > > ______________________________ > > Elinor K. Irish > > Dept. of Physics and Astronomy > > University of Rochester > > Rochester, NY 14627 USA > > eirish at pas.rochester.edu > > > > > > > > Elinor, Your problem is present in the order of evaluation (it has nothing to do with Plot itself): In[29]:= func /. n -> 40; In[30]:= % /. q -> 5.5 Out[30]= 2.44538 In[31]:= func /. q -> 5.5 Out[31]= 2.3197546274792352`*^-14 LaguerreL[n, 60.5`] In[32]:= % /. n -> 40 Out[32]= -0.0245297 This is just one of the pitfalls of numerics. Compare to In[44]:= q0 = SetPrecision[5.5, 50]; In[45]:= func /. n -> 40; In[46]:= % /. q -> q0 Out[46]= -0.024529659209241588039810004526 In[47]:= func /. q -> q0; In[48]:= % /. n -> 40 Out[48]= -0.0245296592092415880398100045256201358100300701381 -- Hartmut Wolf