Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Re: Numerical integration inside numerical integration

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48835] Re: Numerical integration inside numerical integration
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 18 Jun 2004 02:13:04 -0400 (EDT)
  • Organization: The University of Western Australia
  • References: <cark1d$r7v$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <cark1d$r7v$1 at smc.vnet.net>, blah12 at mail.com 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 
numeric.

Cheers,
Paul

-- 
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 physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • 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