Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg87817] Re: Numerical integration and list of points
  • From: antononcube <antononcube at gmail.com>
  • Date: Fri, 18 Apr 2008 02:37:26 -0400 (EDT)
  • References: <ftvd4f$d89$1@smc.vnet.net> <fu1u4g$omu$1@smc.vnet.net>

Sometimes using Integrate can be faster than using NIntegrate. With
your example this is not true, if version 6.0 and higher is used:

In[1]:= $Version
Out[1]= "6.0 for Mac OS X x86 (32-bit) (June 19, 2007)"

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

In[5]:= Integrate[f[x], {x, 0, 20}] ; // Timing
Out[5]= {0.081263, Null}

In[6]:= NIntegrate[Sin[x^2], {x, 0, 20}] ; // Timing
Out[6]= {0.022355, Null}

Anton Antonov
Wolfram Research, Inc.



On Apr 15, 6:50 am, Szabolcs Horv=E1t <szhor... at gmail.com> wrote:

>
> Hi,
>
> Try using Integrate instead ofNIntegrate.  Integrate[] supports
> InterpolatingFunction objects directly, so this will be much faster than
> usingNIntegrate[].
>
> (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: Indefinite numbers of arguments in a function
  • Next by Date: Built-in DatePlus and DateDifference are much slower than DaysPlus
  • Previous by thread: Re: Numerical integration and list of points
  • Next by thread: mx files