>>> from sympy import Symbol, solve, pprint
>>> a=Symbol('a')
>>> b=Symbol('b')
>>> c=Symbol('c')
>>> expr = a*x*x + b*x + c
>>> solve(expr)
[{a: -(b*x + c)/x**2}]
>>> solve(expr,x, dict=True)
[{x: (-b + sqrt(-4*a*c + b**2))/(2*a)}, {x: -(b + sqrt(-4*a*c + b**2))/(2*a)}]
>>> pprint(solve(expr,x, dict=True))
⎡⎧ _____________⎫ ⎧ ⎛ _____________⎞⎫⎤
⎢⎪ ╱ 2 ⎪ ⎪ ⎜ ╱ 2 ⎟⎪⎥
⎢⎨ -b + ╲╱ -4⋅a⋅c + b ⎬ ⎨ -⎝b + ╲╱ -4⋅a⋅c + b ⎠⎬⎥
⎢⎪x: ─────────────────────⎪, ⎪x: ───────────────────────⎪⎥
⎣⎩ 2⋅a ⎭ ⎩ 2⋅a ⎭⎦
>>>
-
-
Save amitsaha/5787802 to your computer and use it in GitHub Desktop.
A bit of SymPy:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment