Re: Numerical integration and list of points

• To: mathgroup at smc.vnet.net
• Subject: [mg87691] Re: Numerical integration and list of points
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Tue, 15 Apr 2008 06:50:20 -0400 (EDT)
• Organization: University of Bergen
• References: <ftvd4f\$d89\$1@smc.vnet.net> <fu1u4g\$omu\$1@smc.vnet.net>

```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 :)

Hi,

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!)

Example:

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.)

Szabolcs

```

• 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