Search code examples
pythonsymbolic-math

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


Solution

  • from sympy import *
    x, y = symbols('x, y')
    expr = x + y + 5
    solve(expr, x)
    >>>Out: [-5-y]