Wrong result of sympy integration with symbol limits

115 views Asked by At
from sympy import *
s = Symbol("s")
y = Symbol("y")
raw_function = 1/(150.0-0.5*y)
result = integrate(raw_function, (y, 0, s)

The above snippet gets a wrong result: -2.0*log(0.5*s - 150.0) + 10.0212705881925 + 2.0*I*pi, but we can know the right result is -2.0*log(-0.5*s + 150.0) + 10.0212705881925, so what's wrong?

1

There are 1 answers

0
Learning is a mess On

Are you sure about the correct result, WolframAlpha says it is the same as Sympy here.

Edit:

This function diverges (and the integral too) around y=300, see its plot here (it diverges the same way as 1/x does but offset to y=300)

enter image description here

Meaning that you are constrained to s < 300 to have a well defined (and finite) integrale. In that range, the value of the integral is equal to what sympy is providing you.