Skip to content
Advertisement

Python: Equation symbolic solution

I was wondering if there was any way I could get the symbolic solution for a variable in an equation using python, as I’ve been looking around but didn’t find exactly what I wanted. What I intend to do is, for example, given:

eq = x + y + 5

I’d like to get:

x = - 5 - y

Advertisement

Answer

from sympy import *
x, y = symbols('x, y')
expr = x + y + 5
solve(expr, x)
>>>Out: [-5-y]
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement