MathGroup Archive 2004

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

Search the Archive

Re: Numerical integration inside numerical integration

In article <cark1d$r7v$1 at>, blah12 at wrote:

> I'm trying to solve numerically an integral like,
> A=some_value
> NIntegrate[f[y,u]*Log[1+NIntegrate[g[y,u,s], {s, A, \[Infinity]}]],
>     {u, -\[Infinity],\[Infinity]},{y, -\[Infinity],\[Infinity]}]
> I know I am doing this wrong as the inner integration fails because
> it doesn't have specific numerical values for y and u.
> I guess Mathematica doesn't perform numerical integrations from the
> outside to the inside (and so passing each time values of y,u to
> the inner integration).

It does not fail. Consider the following example:

  g[y_, u_, s_] := Exp[-s] (Exp[u^2 + 2y^2] - 1)

  f[y_, u_] := Exp[-(u^2 + y^2)]

For these g and f we can compute the integral in closed form:

  Simplify[Log[Integrate[g[y, u, s], {s, 0, Infinity}] + 1],
    {u, y} \[Element] Reals]

  Integrate[f[y, u] %, {u, -Infinity, Infinity}, 
    {y, -Infinity, Infinity}]

If we use NIntegrate instead of Integrate (your integral with A = 0),

  NIntegrate[f[y, u] Log[NIntegrate[g[y, u, s], {s, 0, Infinity}] + 1], 
    {u, -Infinity, Infinity}, {y, -Infinity, Infinity}]

then, after a couple of NIntegrate::"inum" messages (which arise, as you 
suspected, because the inner NIntegrate attempts to evaluate its 
argument before the values of u and y are passed to its integrand), we 
get the same answer as from the exact computation.
Defining the function

  h[y_, u_?NumericQ] := f[y, u] Log[NIntegrate[g[y, u, s], 
    {s, 0, Infinity}] + 1]

allows one to compute the integral without any error message,
  NIntegrate[h[y, u], {u, -Infinity, Infinity}, {y, -Infinity, Infinity}]

because the argument of NIntegrate is now not evaluated unless u is 


Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at 

  • Prev by Date: Re: Controlling function arguments
  • Next by Date: Re: Symbolic use of numerical function FindRoot via ?NumericQ
  • Previous by thread: Re: Numerical integration inside numerical integration
  • Next by thread: Mathe. links for Excel; How to deploy FindMinimum