Reputation: 13150
I'm not able to solve this indefinite integral with Sympy. I checked with Wolfram Alpha, and it clearly converges.
import sympy as sp
a, b, C = sp.symbols("a, b, C", real=True)
E = sp.symbols("E", real=True, positive=True)
chi = C * sp.exp(-a * E) * sp.sinh(sp.sqrt(b * E))
sp.integrate(chi, E)
I tried to rewrite the expression in terms of exponential functions, with no luck:
sp.integrate(chi.rewrite(sp.exp).expand().powsimp(), E)
I've also tried to specify the different algorithms, ie, meijerg=True, than risch=True... Didn't work.
Is it possible to solve it with Sympy? What could be causing this behavior?
Upvotes: 1
Views: 2384
Reputation: 91490
If integrate
returns an unevaluated integral, that means none of the algorithms know how to evaluate the integral. Setting the various options to True does nothing, as they are all tried by default anyway (they are only there if you want to try a specific algorithm).
You might be able to get something SymPy can integrate if you rewrite the hyperbolic sin as exponentials (rewrite(exp)
), do a substitution sqrt(E) = x
(SymPy can do this for you with Integral.transform(sqrt(E), x)
), then complete the square in the exponentials.
Upvotes: 3
Reputation: 13150
Thanks @asmeurer for the suggestion to use the method transform()
. I tried to edit his answer to include the code for the solution, sadly it was rejected.
To the code:
# added positive=True, necessary to solve this integral
a = sp.symbols("a", real=True, positive=True)
b, C = sp.symbols("b, C", real=True)
E = sp.symbols("E", real=True, positive=True)
chi = C * sp.exp(-a * E) * sp.sinh(sp.sqrt(b * E))
f = chi.rewrite(sp.exp).expand().powsimp()
x = sp.symbols("x", real=True, positive=True)
r = f.func(*[sp.Integral(a, E).transform(sp.sqrt(E), x).doit() for a in f.args])
r = r.subs(x, sp.sqrt(E))
Note that I could have use sp.Integral(f, E).transform(sp.sqrt(E), x).doit()
, but it would take at least a few minutes to compute.
By using the linearity property of integrals, I applied the integral to the different terms of the expression with the command r = f.func(...)
. Computation time went down to a few seconds!
Upvotes: 1