Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to integrate with relational operators in SymPy?

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))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading