问题
If I do:
from sympy import *
x, L = symbols('x L', real=True)
f = Piecewise((1, x<=0), (-1, x<1), (0, True))
g = exp(-x * 1j)
integrate(f * g, (x, 0, L))
I get:
Piecewise((1.0*I*exp(-1.0*I*L) - 1.0*I, L <= 0), (-1.0*I*exp(-1.0*I*L) + 1.0*I, L < 1), (-1.0*I*exp(-1.0*I) + 1.0*I, True))
But if I change the last line to:
integrate(f*g, (x, L/2, L))
I get:
Integral(Piecewise((exp(-1.0*I*x), x <= 0), (-exp(-1.0*I*x), x < 1), (0, True)), (x, L/2, L))
Any insight would be appreciated!
回答1:
I guess it's not implemented yet. It probably doesn't know how to deal with the case where both limits are symbolic. You should report it.
A workaround is integrate(f*g, (x, 0, L)) - integrate(f*g, (x, 0, L/2))
.
来源:https://stackoverflow.com/questions/21966759/sympy-fails-to-integrate-the-product-of-a-piecewise-continuous-function-and-a-co