MathGroup Archive 1996

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

Search the Archive

Re: Two Dimensional Numerical Integration Packages

  • To: mathgroup at
  • Subject: [mg4609] Re: Two Dimensional Numerical Integration Packages
  • From: hamlin_m at (Michael Hamlin)
  • Date: Wed, 21 Aug 1996 03:25:26 -0400
  • Organization: MSU Dept. of Physics & Astronomy
  • Sender: owner-wri-mathgroup at

In article <4t8dvr$qcd at>, saarinen at (Sirpa Saarinen) writes:
>Harald Berndt <haraldb at> writes:
>>Matthew Pettis wrote:
>>>         Is there a two dimensional numerical integration
>>> package somewhere out there?  I could not find one in
>>I don't quite see why you need one. Example:
>>f[x_, y_] := Sin[x + Sin[y]]
>>In[5]:= NIntegrate[ NIntegrate[ f[x, y], {x, 0, 5} ], {y, 0, 5} ]
>>Out[5]= 2.07016
>You can also use NIntegrate directly:
>In[1]:= f[x_, y_] := Sin[x + Sin[y]]
>In[2]:= NIntegrate[f[x,y],{x,0,5},{y,0,5}]
>Out[2]= 2.07016
And this latter choice, the two dimensional NIntegrate, is usually better
than calling NIntegrate twice (either nested as given above, or
using delayed definitions), in my experience, because it consumes less 
CPU and real time.
To investigate this a bit, I tried the following experiment, and was surprised
by the result that the nested 1 dimensional NIntegrate was faster!!  I'd
never seen this in my experience before.
Shocked, I tried something a perhaps bit more numerical, to make sure I
wasn't deluding myself...

ni1 := Timing[NIntegrate[NIntegrate[ f[x,y], {x,0,5} ], {y,0,5} ]]
ni2 := Timing[NIntegrate[f[x,y],{x,0,5},{y,0,5}]]

f[x_,y_] = Sin[x + Sin[y]]
ni1:  {3.17 Second, 2.07016}
ni2:  {10. Second, 2.07016}

f[x_, y_] = BesselJ[x,y]
ni1:  {46.52 Second, 4.83093}
ni2:  {27.79 Second, 4.83093}

Why is this?
I thought I understood NIntegrate's better behavior in 2d in the following 
way:  NIntegrate in two dimensions has a better grasp of a function's
behavior between evaluated points because of the second dimension, and
thus doesn't need to evaluate quite so many points in the two dimensional
space.  This could be completely incorrect.
Now that I've seen the above, I am baffled.

				hamlin_m at


  • Prev by Date: Cylindrical Algebraic Decomposition
  • Next by Date: Re: Trilinear plots
  • Previous by thread: Re: Two Dimensional Numerical Integration Packages
  • Next by thread: Re: bar charts with error bars?