Re: NIntegrate

• To: mathgroup at smc.vnet.net
• Subject: [mg71450] Re: NIntegrate
• From: "dimitris" <dimmechan at yahoo.com>
• Date: Sun, 19 Nov 2006 01:10:06 -0500 (EST)
• References: <ejjvm3\$l6r\$1@smc.vnet.net>

```As Anton Antonov pointed me out the integrand f[x] is an even function
and the integral is over a region symmetric around the origin.

NIntegrate with Method->Automatic
will use that to compute over half of the integration region.

With Method->GaussKronrod, no even integrals handling is done.

dimitris wrote:

> Clear["Global`*"]
>
> Consider the following simple function
>
> f[x_] := Exp[-5*x^2] + 1/2
>
> As far as I know the default setting for the option Method of
> NIntegrate is the Gauss-Kronrod algorithm for 1D integrals.
>
> In view of this note I can't understand the difference between the
> outputs of
>
> Reap[NIntegrate[f[x], {x, -3, 3}, Method -> Automatic,
> EvaluationMonitor :> Sow[x]]]
> Length[%[[2,1]]]
>
> and
>
> Reap[NIntegrate[f[x], {x, -3, 3}, Method -> GaussKronrod,
> EvaluationMonitor :> Sow[x]]]
> Length[%[[2,1]]]
>
>
> The following user defined functions will demostrate better the
> difference in the sampled points between the two settings of the Method
> option:
>
> NIntSampledPointsPlot[f_, {x_, a_, b_}, method_, {optsint___},
> {optsplot___}] :=
>   Block[{lst = {}}, lst = Reap[NIntegrate[f, {x, a, b}, Method ->
> method, optsint, EvaluationMonitor :> Sow[x]]];
>     ListPlot[lst[[2,1]], optsplot, PlotLabel ->
> StringJoin["method\[Rule]", ToString[method], ",  sampled points: ",
>        ToString[Length[lst[[2,1]]]], "\nestimate value: ",
> ToString[lst[[1]]]]]]
>
> NIntLinePlot[f_, {x_, a_, b_}, method_, {optsint___}, {optsplot___}] :=
>
>   Block[{lst = {}, ff}, ff = Function[{x}, f]; lst = Reap[NIntegrate[f,
> {x, a, b}, Method -> method, optsint,
>        EvaluationMonitor :> Sow[x]]]; Show[(Graphics[{Red, Line[{{#1,
> 0}, {#1, ff[#1]}}]}] & ) /@ lst[[2,1]], optsplot]]
>
> Then
>
> (NIntSampledPointsPlot[f[x], {x, -3, 3}, #1, {PrecisionGoal -> 20,
> WorkingPrecision -> 30},
>     {ImageSize -> 600, PlotStyle -> PointSize[0.01], Frame -> {True,
> True, False, False},
>      TextStyle -> {FontFamily -> "Times"}}] & ) /@ {GaussKronrod,
> Automatic}
> (*plot to be displayed*)
>
> Show[GraphicsArray[(NIntLinePlot[Exp[-5*x^2] + 1/2, {x, -3, 3}, #1, {},
> {Frame -> True, DisplayFunction -> Identity,
>        PlotLabel -> ToString[#1]}] & ) /@ {Automatic, GaussKronrod}],
> ImageSize -> 800]
> (*plot to be displayed*)
>
>
> Thanks in advance
> Dimitris

```

• Prev by Date: Re: Re: will someone explain the behavior of Unevaluated in this example?
• Next by Date: Converting an expression to a list of terms?
• Previous by thread: Re: NIntegrate
• Next by thread: Wolfram Workbench 1.0 - usage pop-ups