MathGroup Archive 2008

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

Search the Archive

Re: Numerical integration and list of points

guerom00 wrote:
> Thank you for your answers. So this IS indeed the right method.
> After some tests, it's just that my list contains 20'000 elements and
> the integration takes forever to finish...
> I thought Mathematica crashed because I thought it was a rather simple
> thing to do but it turns out I would need to run this integration on a
> powerful cluster or something :)


Try using Integrate instead of NIntegrate.  Integrate[] supports 
InterpolatingFunction objects directly, so this will be much faster than 
using NIntegrate[].

(I found out that Integrate can do this only because your message 
prompted me to experiment, so thanks for this!)


In[1]:= f =
   Interpolation@Table[{x, Sin[x^2]}, {x, 0., 20, 20/20000}];

In[2]:= Integrate[f[x], {x, 0, 20}] // Timing
Out[2]= {0.25, 0.639816}

Check result:

In[3]:= NIntegrate[Sin[x^2], {x, 0, 20}]
Out[3]= 0.639816

(Indeed, NIntegrating this takes a very long time.  I haven't had the 
patience to wait for it to finish.)


  • Prev by Date: Re: Package to 'graft' Lists onto Matrices
  • Next by Date: Re: Solving equations and inequalities with Reduce - how?
  • Previous by thread: Re: Numerical integration and list of points
  • Next by thread: Re: Numerical integration and list of points