MathGroup Archive 2008

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

Search the Archive

Re: Numerical integration and list of points

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87702] Re: Numerical integration and list of points
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 16 Apr 2008 04:59:02 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • 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 :)

Before going to the extremes, like using a cluster, you should try 
*Integrate[]* rather than *NIntegrate[]*. The symbolic integration tool 
*Integrate[]* works very well over *InterpolatingFunction* object and it 
is way faster (anything between about 40 and 100 times faster on my 
system). For instance, it can integrate over 100,000 points in 3/4th of 
a second.

In[1]:= data = RandomReal[{-1000, 1000}, {10, 2}];
f = Interpolation[data];
Timing@Integrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}]
Timing@NIntegrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}]
%[[1]]/%%[[1]]

Out[3]= {0.000163, -867887.}

Out[4]= {0.017414, -867887.}

Out[5]= 106.834

In[6]:= data = RandomReal[{-1000, 1000}, {100000, 2}];
f = Interpolation[data];
Timing@Integrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}]

Out[8]= {0.79024, -3.53364*10^7}

In[9]:= $Version

Out[9]= "6.0 for Mac OS X x86 (64-bit) (February 7, 2008)"

Regards,
-- Jean-Marc



  • Prev by Date: Re: Grid and SpanFromLeft
  • Next by Date: Re: Package to 'graft' Lists onto Matrices
  • Previous by thread: Re: Numerical integration and list of points
  • Next by thread: Re: Numerical integration and list of points