MathGroup Archive 2006

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

Search the Archive

confusion about sampled points in NIntegrate[...,Method->Oscillatory]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69519] confusion about sampled points in NIntegrate[...,Method->Oscillatory]
  • From: dimmechan at yahoo.com
  • Date: Thu, 14 Sep 2006 06:56:57 -0400 (EDT)

Dear all,

***I am very confused about the points sampled by NIntegrate when the
option
Method->Oscillatory is selected.
***This message is in connection with two recent post of mine about
NIntegrate and
some topics discussed in private email communication with Mr Antonov.

***Let me state my problem.
***(I have converted the Outs in InputForm)

Remove["Global`*"]
$Version
5.2 for Microsoft Windows (June 20, 2005)

***Consider the following rapidly oscillatory function (adopted by the
Mathematica Book)

hh[x_]:=ArcTan[3/x] Sin[-9 x]

***Here is its plot

Plot[hh[x],{x,0,10},PlotPoints\[Rule]1000];

***The analytic result of the integral over the range {x,0,Infinity} is
known

Integrate[hh[x],{x,0,Infinity}]//Timing
{11.094000000000001*Second, ((-1 + E^(-27))*Pi)/18}
N[%[[2]]]
-0.1745329251991049

***Since the integrand is a highly oscillatory function, for the
numerical integration, the option
Method->Oscillatory has to be used. Indeed we have

NIntegrate[hh[x],{x,0,Infinity},Method\[Rule]Oscillatory]
-0.174532925199098

***Previous command is equivalent to

NIntegrate[hh[x],{x,0,3(1/9)Pi}]+NSum[NIntegrate[hh[x],{x,k(1/9)Pi,(k+1)(1/9)Pi}],{k,3,8},Method\[Rule]SequenceLimit,VerifyConvergence\[Rule]False]
NIntegrate::nlim: x = 0.349066 k is not a valid limit of integration.
More...
-0.17453292519909863

***We can take a picture of the sampled points executing the following
commands

Block[{Message},ListPlot[Reap[NIntegrate[hh[x],{x,0,3(1/9)Pi},EvaluationMonitor\[RuleDelayed]Sow[x]]+NSum[NIntegrate[hh[x],{x,k(1/9)Pi,(k+1)(1/9)Pi},EvaluationMonitor\[RuleDelayed]Sow[x]],{k,3,8},Method\[Rule]SequenceLimit,VerifyConvergence\[Rule]False]][[2,1]]]];

Block[{Message},Take[Sort[Reap[NIntegrate[hh[x],{x,0,3(1/9)Pi},EvaluationMonitor\[RuleDelayed]Sow[x]]+NSum[NIntegrate[hh[x],{x,k(1/9)Pi,(k+1)(1/9)Pi},EvaluationMonitor\[RuleDelayed]Sow[x]],{k,3,8},Method\[Rule]SequenceLimit,VerifyConvergence\[Rule]False]][[2,1]]],-10]]
{10.139284367498096, 10.165815661890052, 10.203461962943678,
10.248637872782691, 10.297442586766543, 10.346247300750395,
 10.391423210589409, 10.429069511643034, 10.45560080603499,
10.469197883309834}

Block[{Message},Length[Reap[NIntegrate[hh[x],{x,0,3(1/9)Pi},EvaluationMonitor\[RuleDelayed]Sow[x]]+NSum[NIntegrate[hh[x],{x,k(1/9)Pi,(k+1)(1/9)Pi},EvaluationMonitor\[RuleDelayed]Sow[x]],{k,3,8},Method\[Rule]SequenceLimit,VerifyConvergence\[Rule]False]][[2,1]]]]
374

***I also give another implementation below

psum[i_?NumberQ]:=NIntegrate[hh[x],{x,i(1/9)Pi,(i+1)(1/9)Pi}]

***Indeed

NSum[psum[i],{i,0,8},Method\[Rule]SequenceLimit,VerifyConvergence\[Rule]False]
-0.1745329251991767

***Consider now the following function which keeps track of the points
at which is evaluated, in a list called sampledPoints.

sampledPoints={};
f[x_?InexactNumberQ]:=(AppendTo[sampledPoints,x];-ArcTan[3/x])

***Then

NIntegrate[f[x]*Sin[9x],{x,0,8},Method\[Rule]Oscillatory]
-0.17453292519909797

***However, executing the following commands we get the idea that there
are almost 4000 sampling points!

ListPlot[sampledPoints];

Length[sampledPoints]
Take[Sort[sampledPoints],-10]
3894
{10.44054345916208, 10.450522511804508, 10.451837436621835,
10.455600806034992, 10.461249011885242, 10.463788159000485,
 10.46788183548323, 10.469197883309835, 10.470586697637906,
10.47128110480194}

***I do not understand why now exists this big difference in the
sampling points.
Note that executing the next commands show that the two approaches (the
first with Reap...Sow, the second with AppendTo) give the same list of
sample points.

Block[{Message}, ListPlot[Reap[NIntegrate[f[x]*Sin[
    9x], {x, 0, 8}, EvaluationMonitor :> Sow[x]]][[2, 1]]]];

Block[{Message},Length[Reap[NIntegrate[f[x]*Sin[9x],{x,
        0,8},EvaluationMonitor\[RuleDelayed]Sow[x]]][[2,1]]]]
Block[{Message},Take[Sort[Reap[NIntegrate[f[x]*Sin[9x],{x,0,8},
            EvaluationMonitor\[RuleDelayed]Sow[x]]][[2,1]]],-10]]
286
{1.6450911229012775*^121, 7.90974973956965*^148,
1.2071519139393426*^219, 7.896745283035607*^226,
1.062918546484252*^297,
 2.4757019220196006173898`12.794780256164476*^437,
1.919439682574022125136508`12.684318731436761*^593,
 1.04128882331236489972245636`12.65145265080011*^874,
1.8421157385530938933169`12.152934941119156*^1747,
 5.7651196534308263012430262`12.049230617533084*^3493}

***and

sampledPoints={};
Block[{Message},NIntegrate[f[x]*Sin[9x],{x,0,8}]]
1.8915013450362048

Block[{Message},ListPlot[sampledPoints,PlotStyle\[Rule]PointSize[0.015]]];

Length[sampledPoints]
Take[Sort[sampledPoints],-10]
286
{1.6450911229012775*^121, 7.90974973956965*^148,
1.2071519139393426*^219, 7.896745283035607*^226,
1.062918546484252*^297,
 2.4757019220196006173898`12.794780256164476*^437,
1.919439682574022125136508`12.684318731436761*^593,
 1.04128882331236489972245636`12.65145265080011*^874,
1.8421157385530938933169`12.152934941119156*^1747,
 5.7651196534308263012430262`12.049230617533084*^3493}

***Note that you cannot apply the Reap...Sow approach directly since

Reap[NIntegrate[f[x]Sin[9x],{x,

0,8},Method\[Rule]Oscillatory,EvaluationMonitor\[RuleDelayed]Sow[x]]]
{-0.17453292519909797, {{x}}}

Other approaches fail also

psum2[i_?NumberQ]:=Reap[NIntegrate[hh[
  x],{x,i(1/9)Pi,(i+1)(1/9)Pi},EvaluationMonitor\[RuleDelayed]Sow[x]]]

NSum[psum2[i],{i,0,Infinity},Method->SequenceLimit,VerifyConvergence->False]
NSum::nsnum: Summand (or its derivative) psum2[i] is not numerical at
point i = 15. More...
NSum[psum2[i], {i, 0, Infinity}, Method -> SequenceLimit,
VerifyConvergence -> False]

psum3[i_?NumberQ]:=NIntegrate[hh[x],{x,i(1/9)Pi,(i+1)(1/9)Pi}]

Reap[NSum[psum3[i],{i,0,Infinity},Method->SequenceLimit,VerifyConvergence->False,EvaluationMonitor:>Sow[i]]]
{-0.17453292519917665, {{15., 16., 17., 18., 19., 20., 21., 22., 23.,
24., 25., 26., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.,
13., 14.}}}


***I really appreciate some guidance.
***Thanks in advance for any assistance.

Dimitrios Anagnostou
NTUA


  • Prev by Date: Re: Locating common subexpressions
  • Next by Date: Re: Re: Re: solve and Abs
  • Previous by thread: Re: (again) common problem with FindMinimum and NIntegrate
  • Next by thread: Calculation of a very ugly integral