Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / Mathematica / December 2006



Tip: Looking for answers? Try searching our database.

Speeding up HermiteH[Range[0,p],x]

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
erwann.rogard@gmail.com - 21 Dec 2006 10:43 GMT
hi,

Looking at Out[6] and Out[8] it seems --unfortunately- that
HermiteH[Range[0,p],x] simply performs a map over Range[0,p] because if
the recurrence relation for hermite polynomials was used, we would
expect Out[6] about twice smaller than Out[8] (i think). The redefined
function, myHermiteH, which uses the recurrence relation is not
competitive for p<60. Would someone know of a way to improve speed?

thanks,

e.

In[1]:=
ClearAll[myHermiteH]
rec=Compile[{{n,_Integer},{x,_Real},{h1,_Real},{h0,_Real}},2(x
h1-(n-1)h0)];
myHermiteH[p_,x_]:=Module[{h},Join[{h[0]=1,h[1]=2x},
Array[With[{n=#+1},h[n]=rec[n,x,h[n-1],h[n-2]]]&,{p-1}]]];

In[4]:=
ar=Array[Random[]&,{2^10}];
rng=Range[0,p=10];

In[6]:=
Timing[HermiteH[rng,#]&/@ar;]
Timing[myHermiteH[p,#]&/@ar;]
Timing[Outer[HermiteH,rng,ar];]

Out[6]=
{0.096006 Second,Null}
Out[7]=
{0.31602 Second,Null}
Out[8]=
{0.080005 Second,Null}
David Bailey - 25 Dec 2006 10:08 GMT
Hello,

I think what you are asking is why, in expressions such as
HermiteH[Range[0,p],x], Mathematica does not do what a mathematician
might do, and calculate one value from the previous one using a
recurrence relation. However, can you imagine the number of special
cases of this sort that would have to be coded into Mathematica software
to make this a reality! Also, at least for some functions, the repeated
use of a recurrence relation might build up rounding errors if x is numeric.

David Bailey
http://www.dbaileyconsultancy.co.uk
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.