Here is what Maple gives:
> int(C * x**2 * exp(-x/kT), x=xmin..infinity);
/ 3 / x \ 2 / x \ 2 / x \
limit|-2 kT C exp|- --| - 2 kT C exp|- --| x - kT C x exp|- --|
\ \ kT/ \ kT/ \ kT/
3 / xmin\ 2 / xmin\ / xmin\ 2
+ 2 kT C exp|- ----| + 2 kT C exp|- ----| xmin + kT C exp|- ----| xmin ,
\ kT / \ kT / \ kT /
\
x = infinity|
/
> assume(kT, positive);
> int(C * x**2 * exp(-x/kT), x=xmin..infinity);
/ 2 2\ / xmin\
kT \2 kT + 2 xmin kT + xmin / C exp|- ----|
\ kT /
The last one is the same as the result Ronan gave when you correctly make SymPy
assume kT is positive. Also note the call to make Maple assume kT is positive.
You can hardly blame Dan for believing that SymPy's Assume() does the same
thing!
The SymPy bug is in the limit engine, not the integral engine:
In [72]: print integrate(C * x**2 * exp(-x/kT), (x, xmin, y))
C*(-2*kT**3*exp(-y/kT) - kT*y**2*exp(-y/kT) - 2*y*kT**2*exp(-y/kT)) -
C*(-2*kT**3*exp(-xmin/kT) - kT*xmin**2*exp(-xmin/kT) -
2*xmin*kT**2*exp(-xmin/kT))
In [73]: print limit(integrate(C * x**2 * exp(-x/kT), (x, xmin, y)), y, oo)
-oo - C*(-2*kT**3*exp(-xmin/kT) - kT*xmin**2*exp(-xmin/kT) -
2*xmin*kT**2*exp(-xmin/kT))
Judging by the Maple result, limit() shouldn't be able to do anything with it
unless it knows that kT is positive.
To answer your question Dan, yes, please report this in our issue tracker.
Aaron Meurer
May 20, 2010, at 4:59 AM, Dan wrote:
> Hi Ronan,
>
> Thanks you much for clearing this up: my assumption about Assume() was
> incorrect!
>
> What is the expected output without using Symbol('kT', positive=True)?
> Should I report this as a bug?
>
> Best regards,
>
> Dan
>
> On May 20, 10:32 am, Ronan Lamy <[email protected]> wrote:
>> Le jeudi 20 mai 2010 à 01:48 -0700, Dan a écrit :
>>
>>
>>
>>
>>
>>> Hi folks,
>>
>>> I'm trying to integrate a function but I can't understand why sympy is
>>> producing the wrong output.
>>
>>> The equation is,
>>
>>> var('C E kT xmin')
>>> Assume(kT > 0)
>>> Assume(xmin >=0)
>>> integrate(C * x**2 * exp(-x/kT), (x, xmin, oo))
>>
>>> which gives,
>>> -oo - C*(-2*kT**3*exp(-xmin/kT) - kT*xmin**2*exp(-xmin/kT) -
>>> 2*xmin*kT**2*exp(-xmin/kT))
>>
>>> This is correct apart from negative infinity the appears at the
>>> beginning. Am I doing something wrong?
>>
>>> When I tried this with Maxima is asked what the sign of kT is (hence
>>> the use of Assume above), but it then goes on to give the correct
>>> answer. Help very much appreciated.
>>
>> Despite the name, Assume doesn't do anything, it's just an inert object.
>> To do what you want, you need:
>>
>> kT = Symbol('kT', positive=True)
>>
>> With that, it works:
>>
>> In [11]: print integrate(C * x**2 * exp(-x/kT), (x, xmin, oo))
>> -C*(-2*kT**3*exp(-xmin/kT) - kT*xmin**2*exp(-xmin/kT) -
>> 2*xmin*kT**2*exp(-xmin/kT))
>>
>> The fact that you get a result containing oo is, obviously, a bug.
>>
>> Ronan
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sympy" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group
>> athttp://groups.google.com/group/sympy?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.