I'm not a SymPy
expert, but I've used it successfully in some of my lectures in the last years. However, sometimes it seems to be very slow with symbolic integration. Here's an example that Mathematica
computes almost instantly while SymPy
needs a long time (more than half a minute) for it on my machine.
from sympy import *
x = symbols("x")
def coeff (f, k, var = x):
return integrate(f(var) * cos(k * var), (var, -pi, pi)) / pi
f = lambda x: (11*sin(x) + 6*sin(2*x) + 2*sin(3*x))/10
[coeff(f, k) for k in range(0, 5)]
Am I doing something wrong or is this the expected behavior? Is there some trick to speed this up?
SymPy
version is 1.0, Python
is 3.5.1 64-Bit (Anaconda) on Windows.