I want to solve the cubic equation easily ... The formula for the solution of the cubic equation is extremely long. If you are interested here When I searched for a programmatic solution to this, there was a module called sympy in Python. Really awesome.
Both worked
windows 10
Python 3.7
Ananconda
It's already installed in Anaconda's environment, but if not, install it with pip
pip install sympy
I want to solve the equation for the time being! Click here
You can define characters with Symbol
and solve equations withsolve ()
.
Solve the following cubic equation.
3x^3 + 2x^2 + x + 10 = 0
Exponentiation can be written in Python's standard exponentiation style.
x**3 #x cubed
The following is the program.
from sympy import *
x = Symbol('x')
sol = solve(3*x**3 + 2*x**2 + x + 10)
print(sol)
Output result. Three solutions are passed in list.
[-5/3, 1/2 - sqrt(7)*I/2, 1/2 + sqrt(7)*I/2]
This is the same as below.
[\frac{-5}{3}, \frac{1}{2} - \frac{{\sqrt{7}}i}{2}, \frac{1}{2} + \frac{{\sqrt{7}}i}{2}]
~ Under investigation ~ Append
Recommended Posts