Re: NIntegrate
- To: mathgroup at smc.vnet.net
- Subject: [mg44829] Re: [mg44794] NIntegrate
- From: Anton Antonov <antonov at wolfram.com>
- Date: Wed, 3 Dec 2003 04:24:10 -0500 (EST)
- References: <200311271638.LAA19984@smc.vnet.net> <3FC63D70.9030906@wolfram.com> <20031127214003.933EA15D8033@nonlocal>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Zheng,
Now it is clearer! :) Thanks.
Here are my evaluations in InputForm:
In[7]:=Quit
In[1]:=$Version
Out[1]=5.0 for Linux (June 9, 2003)
In[2]:=
Timing[N[Integrate[(x - 1)^0.5*(1/(1 + Exp[(x - 2)/2])), {x, 1, Infinity}]]]
Timing[NIntegrate[(x - 1)^0.5*(1/(1 + Exp[(x - 2)/2])), {x, 1, Infinity}]]
Out[2]= {0.75 Second,2.80073}
Out[3]= {0.01 Second,2.80073}
In[4]:=
Timing[Integrate[(x - 1)^0.5*(1/(1 + Exp[(x - 2)/2])), {x, 1,
Infinity}]]//InputForm
Out[4]//InputForm={0.15000000000000002*Second,
Integrate[(-1 + x)^0.5/(1 + E^((-2 + x)/2)),
{x, 1, Infinity}]}
The first expression calls Integrate, and then N. You can see that In[4]
and Out[4] Integrate doesn't find the integral and gives up. The
Integrate timings in Out[2] and Out[4] are different since Integrate
loads certain packages when it is confronted with a more complicated
integral.
Applying N results to using NIntegrate. After transforming [1,Infinity]
to [0,1], NIntegrate doesn't find the integral difficult at all -- you
can see this with the plot command bellow. (In/Out 6 and 7 calculate the
variable change.)
In[6]:= rep = (x - 1)^0.5*(1/(1 + Exp[(x - 2)/2])) /. x -> 1 + (1 - t)/t
Out[6]=((1 - t)/t)^0.5/(1 + E^((1/2)*(-1 + (1 - t)/t)))
In[7]:=D[1 + (1 - t)/t, t] // Simplify
Out[7]=-(1/t^2)
In[8]:= Plot[rep*(1/t^2), {t, 0, 1}]
This behavior can be seen also for Sum/NSum
In[4]:=Quit
In[1]:=N[Sum[1/(Log[t]*t^2), {t, 2, Infinity}]]//Timing
Out[1]={0.24 Second,0.605522 + 0.*I}
In[2]:=NSum[1/(Log[t]*t^2), {t, 2, Infinity}]//Timing
Out[2]={0.01 Second,0.605522 + 0.*I]}
Here Sum cannot do the summation, it gives up, and NSum is called.
--Anton
Zheng Yang wrote:
> Hi,
>
> Thanks for your reply. My original message was posted in Unicode
> (UTF-8) since the standard ASCII coding doesn't cover the integration
> and infinity characters that were copied&pasted directly from my
> Mathematica notebook. I'm attaching them as plain text and a GIF image
> showing the two expressions below.
>
> \!\(N[\[Integral]\_1\%\[Infinity]\((x - 1)\)^ .5\ \(1\/\(1 +
> Exp[\((x - 2)\)/2]\)\) \[DifferentialD]x]\ \n
>
> NIntegrate[\((x - 1)\)^ .5\ 1\/\(1 + Exp[\((x - 2)\)/2]\), {x,
> 1, \[Infinity]}]\)
>
> Happy Thanksgiving.
>
> Zheng
>
>
> Anton Antonov wrote:
>
>> Zheng Yang wrote:
>>
>>> Hi,
>>>
>>> I'd like to ask why the first expression below takes so much longer
>>> to finish than the second. They look same to me.
>>>
>>> \!\(N[â?«\_1\%â??\((x - 1)\)^ .5\ \(1\/\(1 + Exp[\((x -
>>> 2)\)/2]\)\) \[DifferentialD]x]\)
>>>
>>> \!\(NIntegrate[\((x - 1)\)^ .5\ 1\/\(1 + Exp[\((x - 2)\)/2]\), {x,
>>> 1, â??}]\)
>>>
>>> And I'd like to know if this apply to other numerical functions.
>>>
>>> Thanks a lot,
>>>
>>> Zheng
>>>
>>>
>>
>> Hi,
>>
>> Would you please send the input form of your Mathematica expressions!
>>
>> The meaning of the symbols
>>
>> â?«\_1\%â??\
>>
>> is not clear.
>>
>>
>> It seems to me that your code is incomplete. For example, the second
>> line of your code gives to NIntegrate a symbolic range for the
>> variable x, so NIntegrate doesn't make any calculations.
>>
>> Anton Antonov
>> Wolfram Research, Inc.
>>
>
>
>
> ------------------------------------------------------------------------
>