Home > other >  How to integrate with relational operators in SymPy?
How to integrate with relational operators in SymPy?

Time:04-28

I want to integrate sin((a-b)*x) along x from 0 to pi/4 in sympy. It gives me a piecewise answer for when (a-b)!=0 and (a-b)=0. How do I integrate only for the condition that (a-b)!=0?

I tried the following code with the relational operator but it didn't help.

from sympy import *
a, b, x = symbols("a b x")
Rel(a, b, "ne")
integrate(sin((a-b)*x),(x,pi/4))

CodePudding user response:

You can use conds="none" inside the integrate command:

integrate(sin((a-b)*x),(x,pi/4), conds="none")

Alternatively, you can extract the piece you are interested in from a piecewise result, by exploring its arguments:

res = integrate(sin((a-b)*x),(x,pi/4), conds="none")
final = res.args[0][0]

Edit: Note that the command Rel(a, b, "ne") does nothing. It just creates an unequality that is never being used.

  • Related