Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Two Dimensional Numerical Integration Packages

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

In article <4t8dvr$qcd at dragonfly.wolfram.com>, saarinen at wolfram.com (Sirpa Saarinen) writes:
>Harald Berndt <haraldb at nature.berkeley.edu> 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:
>>In[1]:=
>>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.

				michael
				hamlin_m at pa.msu.edu

==== [MESSAGE SEPARATOR] ====


  • 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?