Question

I tried the following integral in SymPy 0.7.3:

import sympy
from sympy import cos, sin, pi
sympy.var('x, L')
sympy.var('i, k', integer=True)

integrand = cos(pi*i*x/L)**2*cos(pi*k*x/L)**2*sin(pi*i*x/L)*sin(pi*k*x/L)

print(sympy.integrate(integrand, (x, 0, L), conds='none'))

I already tried not using the conds argument and not using integer=True when declaring i, k without success.

Is there any other workaround to solve this integral?

The solution for this integral is 0.

NOTE: There are other similar integrands for which SymPy hangs if someone is interested. I've noticed a trend of SymPy to hang when the simplifications along the integrations lead to 0 terms, so maybe the problem is in a simplification algorithms applied along the integration.

Était-ce utile?

La solution

Unfortunately, currently SymPy's ability to deal with trigonometric integrals is not that great. There are maybe some forms that it will deal with better than others (you can play with trigsimp'ing the input to see if it helps).

If you don't mind dealing with the output, you can rewrite the integrand in terms of complex exponentials. SymPy is much better at integrating those. Use .rewrite(exp). You'll have to use .rewrite(sin) and simplify at the end to get it back in terms of trig functions, though. Unfortunately, it doesn't really help for this particular integral :(

Better trigonometric integration is coming. The work from https://github.com/sympy/sympy/pull/2380 needs to be finished, and one more algorithm implemented.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top