Re: Nested numerical integration
- To: mathgroup at smc.vnet.net
- Subject: [mg99156] Re: Nested numerical integration
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 29 Apr 2009 03:47:16 -0400 (EDT)
On 4/28/09 at 4:45 AM, tsg.moore at googlemail.com wrote:
>Hi, I'd like to compute a nested integral like,
>NIntegrate[ w^2 * NIntegrate[1/(s-w), {s, 1, 5}], {w, -5, -1}]
>Unfortunately, mathematica gives me an error (NIntegrate::inumr) and
>it also outputs the wrong value. Is there a way to do these types of
>integrals?
It gives you an error since the inner integral won't yield a
numerical value since as far as it is concerned w is undefined.
The way to do this is to use more appropriate syntax as shown in
the second example when you look up NIntegrate in the
Documentation Center. That is:
In[2]:= NIntegrate[w^2*1/(s - w), {s, 1, 5}, {w, -5, -1}]
Out[2]= 25.8364
You can easily verify this gives the correct value using
Integrate. That is using the syntax you attempted to use above:
In[3]:= Integrate[w^2*Integrate[1/(s - w), {s, 1, 5}], {w, -5, -1}]
Out[3]= -16-84 log(3)+(250 log(5))/3
which is the same result obtained with:
In[4]:= Integrate[w^2*1/(s - w), {s, 1, 5}, {w, -5, -1}]
Out[4]= -16-84 log(3)+(250 log(5))/3
and
In[5]:= %1 // N
Out[5]= 25.8364
gives the same result as NIntegrate using the appropriate syntax.