Re: A faster alternative to ListIntegrate? postscript
- To: mathgroup at smc.vnet.net
- Subject: [mg35723] Re: A faster alternative to ListIntegrate? postscript
- From: Tom Burton <tburton at brahea.com>
- Date: Sat, 27 Jul 2002 06:43:35 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I should have checked before: Compile doesn't make any difference on my machine. (Used too; old habits die hard;) So roughly as fast and simpler is li[y_,d_]:=Tr[(#[[1]]+#[[2]])d/2&/@Partition[y,2,1]] Tom Burton ------ Forwarded Message From: Tom Burton <tomburton at earthlink.net> To: mathgroup at smc.vnet.net Subject: [mg35723] Re: A faster alternative to ListIntegrate? Hello, Below is a simple-minded implementation that delivers the factor of 10 I previously suggested in private. It's only first order, but you could improve it as needed easily. Tom Burton On 7/26/02 1:21 AM, in article ahr122$l2v$1 at smc.vnet.net, "Matthew Rosen" <mrosen at cfa.harvard.edu> wrote: > Hi Everyone; > I've tracked down the slow operation of my Mathematica simulation code to > lie in the ListIntegrate command: > > G[n_] := ListIntegrate[xsec Phi[n], 1] > > where both xsec and Phi[n] are 400 values long. > > Is there a way to speed up ListIntegrate via Compile or a similar technique? > > Thanks in advance and best regards, In[2]:= <<NumericalMath`ListIntegrate` In[27]:= xsec=4.0;Phi[n_]=Range[400]; In[29]:= G1 := ListIntegrate[xsec Phi[n], 1] In[28]:= G1 Out[28]= 319998. In[30]:= Timing[Do[G1,{200}]] Out[30]= {7.6 Second,Null} In[36]:= li=Compile[{{y,_Real,1},{d,_Real,0}}, Tr[(#[[1]]+#[[2]])d/2&/@Partition[y,2,1]] ]; In[33]:= G2:=li[xsec Phi[n],1] In[34]:= G2 Out[34]= 319998. In[35]:= Timing[Do[G2,{200}]] Out[35]= {0.57 Second,Null} ------ End of Forwarded Message