       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:= \$Version
Out= "6.0 for Mac OS X x86 (32-bit) (June 19, 2007)"

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

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

In:= NIntegrate[Sin[x^2], {x, 0, 20}] ; // Timing
Out= {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:= f =
>    Interpolation@Table[{x, Sin[x^2]}, {x, 0., 20, 20/20000}];
>
> In:= Integrate[f[x], {x, 0, 20}] // Timing
> Out= {0.25, 0.639816}
>
> Check result:
>
> In:=NIntegrate[Sin[x^2], {x, 0, 20}]
> Out= 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