MathGroup Archive 2010

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

Search the Archive

Re: Re: Re: problem with double integral - Very

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107698] Re: [mg107676] Re: [mg107669] Re: problem with double integral - Very
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Tue, 23 Feb 2010 08:04:23 -0500 (EST)
  • References: <hlj3vf$rop$1@smc.vnet.net> <201002230003.TAA26392@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

The following trick isn't necessary for THIS problem, because NIntegrate
converges quickly for the arguments passed to "fun".

Still, it will generally be faster to use NDSolve, when you're planning to
use a lot of different limits for the same integration.

First, Daniel's solution:

fun[Q_?NumericQ] :=
    NIntegrate[(Exp[-1/(4 x) - 4 x]), {x, Q, \[Infinity]}]
{time1, ans1} = Timing@NIntegrate[1/fun[q], {q, 0, 1}]

{0.116869, 71.477}

Now the other solution.

We break the integral from Q to Infinity into two parts, the tail of which
(from 1 to Infinity) is

{time2, tail} =
    Timing[NIntegrate[(Exp[-1/(4 x) - 4 x]), {x, 1, \[Infinity]}]]

{0.002415, 0.0037272}

Then we calculate all the needed values for "fun" (leaving out the tail)
in one go:

Clear[f]
{time3,f}=Timing[f/.First@Quiet@NDSolve[{f'[x]==-Exp[-1/(4 x)-4
x],f[1]==0},f,{x,0,1}]
]
{0.001852,InterpolatingFunction[{{0.00561083,1.}},<>]}

(I used Quiet to stifle a warning that doesn't affect the end result...
this time, anyway.)

Finally,

{time4,ans2}=Timing@NIntegrate[(f[q]+tail)^-1,{q,0,1}]

{0.011817,71.477}

Here are total times for both methods:

{time1, time2 + time3 + time4}

{0.116869, 0.016084}

Divide @@ %

7.26617

NDSolve made the work go 7 times faster than repeatedly using NIntegrate,
and I didn't have to tell NIntegrate that f takes numerical arguments only.

Bobby

On Mon, 22 Feb 2010 18:03:48 -0600, <smcconne at pi0.physi.uni-heidelberg.de>
wrote:

> I just thought it might be useful to highlight this post for searching  
> purposes because this kind of NIntegrate workaround is extremely handy  
> when dealing with a 3 body problem. Specifically because in the three  
> body problem one frequently uses a multipole expansion for the distance  
> between 2 of the particles and the centre of the frame of reference  
> (usually the 3rd particle).
>
> The expansion is  
> Sum[((Min[r,R]^l)/(Max[r,R])^(l+1))LegendreP[Cos[[/gamma]]],{l,0,Infinity}].  
> Of course this two variable expansion usually becomes a part of an  
> integral which is split in order to "simplify" things, but if you don't  
> tell NIntegrate that the arguments are numeric, it will hardly seem like  
> a simplification at all.
>
> I hope many researchers on 3 body systems who conduct a search for how  
> to wedge Mathematica into performing this integral find this thread!!
>
> Sean.
>
> Quoting dh <dh at metrohm.com>:
>
>> Hi Regina,
>> you may do it like:
>>
>> fun[Q_?NumericQ]:= NIntegrate[(Exp[-1/(4 x) - 4 x]), {x, Q,  
>> \[Infinity]}]
>> NIntegrate[1/fun[x], {x, 0, 1}]
>>
>> Note that I changed the order of the limits and defined fun only for
>> numerical arguments. Otherwise NIntegrate is not happy.
>> Daniel
>>
>>
>>
>> On 18.02.2010 11:15, Regina wrote:
>>> Hi there,
>>> i got a problem: how can i evaluate the following integral:
>>> define:
>>> i[Q_] := Integrate[(Exp[-a/(4 x) - 4 x]), {x, \[Infinity], Q}]
>>> now i want to compute:
>>> NIntegrate[1/i[Q], {Q, 0, 1}]
>>>
>>> what am i doing wrong? how can i integrate that function?
>>>
>>
>>
>> --
>>
>> Daniel Huber
>> Metrohm Ltd.
>> Oberdorfstr. 68
>> CH-9100 Herisau
>> Tel. +41 71 353 8585, Fax +41 71 353 8907
>> E-Mail:<mailto:dh at metrohm.com>
>> Internet:<http://www.metrohm.com>
>>
>>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: DiscreteUniformDistribution PDF isn't piecewise?
  • Next by Date: Re: Handheld mathematica
  • Previous by thread: Re: Re: problem with double integral - Very useful for
  • Next by thread: Re: Digitizing plots with Mathematica (i.e. extracting data points