|
[Date Index]
[Thread Index]
[Author Index]
Points sampled by NIntegrate
- To: mathgroup at smc.vnet.net
- Subject: [mg67431] Points sampled by NIntegrate
- From: andrew.j.moylan at gmail.com
- Date: Fri, 23 Jun 2006 04:32:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
[I apologise for the length of this post; I have tried to state my
problem as clearly as possible, and the result is long.]
I am trying to understand how NIntegrate decides at which points to
sample a function when estimating its improper integral over e.g. {1,
Infinity}. Please consider the following code:
sampledPoints = {};
f[r_?NumericQ] :=
(
AppendTo[sampledPoints, r]; 1/(r^2 + Sin[r])
)
NIntegrate[f[r], {r, 1, Infinity}, PrecisionGoal -> 4]
Take[Sort[sampledPoints], -10]
Length[sampledPoints]
The function f is just 1/(r^2 + Sin[r]), except it keeps track of the
points at which it is evaluated, in a list called sampledPoints. After
NIntegrate is called on f over {1, Infinity}, the last two lines
returns the 10 largest values of r for which f[r] was evaluated, and
the number of values of r for which f[r] is evaluated. In the case
above, the following are returned:
{69.3345, 85.2695, 125.67, 130.17, 170.539, 251.341, 341.078, 502.682,
1005.36, 2010.73}
and
99.
Now consider the following code, which is identical except that the
PrecisionGoal option to NIntegrate has been increased from 4 to 5:
sampledPoints = {};
f[r_?NumericQ] :=
(
AppendTo[sampledPoints, r]; 1/(r^2 + Sin[r])
)
NIntegrate[f[r], {r, 1, Infinity}, PrecisionGoal -> 5]
Take[Sort[sampledPoints], -10]
Length[sampledPoints]
The following are now returned by the last two lines:
{1005.363620876827`, 1518.2201755137608`, 2010.727241753654`, \
20094.148354998237`, 34180.18350952692`, 6.859835603121333`*^7, \
1.066219395284406`*^10, 1.931379671660648`*^19, 2.22745842812734`*^55,
\
8.429342764501086`*^109}
and
176.
To me, sampling 176 points instead of 99 seems perfectly reasonable;
but I can't understand the presence of such large numbers as ~10^110 in
the list of sampled points of f. Can anyone explain why they suddenly
emerge as the PrecisionGoal increases?
Now, since 1/(r^2 + Sin[r]) is not (I assume) any more expensive to
compute at ~10^110 than at around ~1, these enormous values at which f
is sampled do not prevent NIntegrate from converging rapidly. However,
I wish to integrate elements of a class of functions that _are_ more
expensive to evaluate at large values of their argument.
The functions I am interested in integrating over {1, Infinity} go to
zero as their argument goes to Infinity (as they must, if they are to
converge) and do so monotonically. Their values at ~10^100 might as
well be zero. By a hack, I could define them to be zero for values of
their argument larger than some cutoff; or I could use only low options
for PrecisionGoal in NIntegrate; but I would prefer to understand what
it is that is making NIntegrate suddenly choose to sample the integrand
at very large values of the argument.
Thanks for any help.
Cheers,
Andrew.
Prev by Date:
Re: Please Help a student...
Next by Date:
Re: Please Help a student...
Previous by thread:
Re: gaussian fit
Next by thread:
Re: Points sampled by NIntegrate
|