Simanamis
Simanamis

Reputation: 1

Sympy returns Integrate when integrating with a constant sometimes

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.

How to make sympy calculate this?

Upvotes: 0

Views: 67

Answers (1)

Davide_sd
Davide_sd

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

Related Questions