Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sympy's solve() command for equations != 0

Tags:

sympy

According to the Sympy docs, the solve() command expects an equation to solve as being equal to 0.

How can I solve equations not in that form?

like image 208
bijan Avatar asked Feb 27 '26 14:02

bijan


1 Answers

What the docs are saying is that if you do something like

>>> solve(x**2 - 1, x)

Then solve is implicitly assuming that x**2 - 1 is equal to 0. If you wanted to solve x**2 - 1 = 2, then you could either subtract 2 from both sides, to get

>>> solve(x**2 - 1 - 2, x)

or you could use the Eq() class

>>> solve(Eq(x**2 - 1, 2), x)
like image 120
asmeurer Avatar answered Mar 02 '26 14:03

asmeurer