Reputation: 1
I am trying to integrate a seemingly simple equation but can't. This is the equation:
sin(x)
------
x + n·pi
So when I do
import sympy as sym
x = sym.Symbol("x")
n = sym.Symbol("n", real = True, constant = True)
sym.integrate(sym.sin(x)/(x+sym.pi*n),x)
I get Integral(sin(x)/(pi*n + x), x)
. I have tried other solutions like .doit()
and .evalf()
but to no avail.
n = 3
or other random number then it works.sym.integrate(sym.sin(x)/(x+sym.pi)/n, x)
. This is obviuosly not the same formula but stillHow to make sympy calculate this?
Upvotes: 0
Views: 67
Reputation: 13150
Sympy's integration algorithms appear to be very sensitive to assumptions. For example, assuming n
to be a positive integer, then SymPy is able to compute the result:
import sympy as sym
x = sym.Symbol("x")
n = sym.Symbol("n", integer=True, positive=True)
res = sym.integrate(sym.sin(x)/(x+sym.pi*n),x)
res
# out: exp(I*pi*n)*Si(pi*n + x)
You can then simplify it:
res.simplify()
# out: (-1)**n*Si(pi*n + x)
Upvotes: 1