I am trying to calculate exact value of an improper integral of 2nd kind with sympy:
from sympy import integrate, log
from sympy.abc import x
print (integrate(log(x) * log(x) /(1+x*x), (x,0,1)))
This code return a lot of mistakes. May be I need to use another approach? I have try with Integral
and got nothing.
I 'd like to calculate these integrals from Dwight tables (863.61 and 863.10):
I may calculate them with numerical methods but rather I'd like to get exact solutions with sympy. Is it possible to get exact solution of an improper integral of the 2nd kind with sympy? Or these integrals are too complicated for sympy?
Floating point numbers are poison for symbolic computations, especially as complicated as symbolic integration. Don't put them in symbolic integrals.
Also, declaring positive variables as such can be a big help.
x = symbols('x', positive=True)
int1 = integrate(log(x)**2 / (1 + x**2), (x, 0, 1))
int2 = integrate(log(1/x) / (1 - x), (x, 0, 1))
No errors now, but int1
is just the original integral un-evaluated; SymPy did not succeed in finding its value. It seems to be beyond its ability.
For the second one it returns polylog(2, -exp_polar(I*pi))
. The presence of complex number I*pi
and exp_polar
means SymPy was doing some complex plane work where the amount of winding around the origin might matter. The function exp_polar
is different from exp
in that exp_polar(2*I*pi)
does not simplify to 1 like exp(2*I*pi)
does: it keeps the distinction between turning by 360 degrees and not turning at all.
But if we ignore all that and put exp
in the result,
polylog(2, -exp(I*pi))
evaluates to pi**2 / 6
, the correct value of the second integral.