Speeding up HermiteH[Range[0,p],x]
- To: mathgroup at smc.vnet.net
- Subject: [mg72347] Speeding up HermiteH[Range[0,p],x]
- From: "erwann.rogard at gmail.com" <erwann.rogard at gmail.com>
- Date: Thu, 21 Dec 2006 05:34:40 -0500 (EST)
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}