A fast, reliable Python library to solve cubic equations of all kinds. You can test out cardano-method
in your browser.
cardano-method
implements Gerolamo Cardano's famous method of solving cubic equations - 'Cardano's Method'. Split amongst various stages of processing, this library mirrors the steps described in Cardano's Method to solve for the roots of a cubic equation.
For a more detailed explanation of the specifics, please refer to the succeeding section discussing the underlying mathematics.
$ pip install cardano-method
from cardano_method import CubicEquation
a = CubicEquation([1, 3, 4, 4])
print(a.roots)
# [(-2+0j), (-0.5+1.322875j), (-0.5-1.322875j)]
Note that the answers
attribute contains a list of complex
objects representing the zeroes of the cubic equation.
Let's say the original cubic was
Cardano Method is applied to a depressed cubic polynomial. Depressed polynomials are those where the coefficient of the
We can use context from Vieta's relations to construct this depressed polynomial,
Notice how the the
From here, to simplify things a bit, let's introduce some variables: (after dividing away to leave a coefficient of 1)
Here, we make an interesting construction. Assume some arbitrary
Equating the final polynomial to the original polynomial, we get
If this looks complicated, don't worry - we agree too! The CardanoMethod package's CubicEquation
handles all of this on the back-end and abstracts away all of the complex math.