一元1次方程
import sympy as sp
x = sp.Symbol('x')
f = 2*x -8
x = sp.solve(f)
x
[4]
一元2次方程
import sympy as sp
x = sp.Symbol('x')
f = 4*x**2 + 2*x -16
x = sp.solve(f)
x
[-1/4 + sqrt(65)/4, -sqrt(65)/4 - 1/4]
一元3次方程
import sympy as sp
x = sp.Symbol('x')
f = 2*(x**3) +3*x**2 + 0.33*x -4.55
x = sp.solve(f)
x
[0.933565672293077,-1.21678283614654 - 0.977922748780713*I,-1.21678283614654 + 0.977922748780713*I]
一元4次方程
import sympy as sp
x = sp.Symbol('x')
f = 2*(x**4)+2*(x**3) +3*x**2 + 0.33*x -4.55
x = sp.solve(f)
x
[-1.19455898403574,0.838243205872661,-0.321842110918462 - 1.47254669319059*I,-0.321842110918462 + 1.47254669319059*I]