functionccubicRoots

Analytical solution for the roots of a cubic equation (a*x^3+b*x^2+c*x+d=0)

Information


Return roots[3] where each root is complex (i.e., has both roots[*].re and roots[*].im ).


nRoots helps to identify the number of expected real roots based on the result from the polynomial discriminant, D.

re and im hold the same roots as Real arrays (roots[i] = Complex(re[i], im[i])). Use them in a model that must also run in OpenModelica, which cannot set an array of Complex records in a model from a function call: (, nRoots, re, im) = ccubicRoots(a, b, c, d);

Inputs

TypeNameDefaultDescription
Reala
Realb
Realc
Reald

Outputs

TypeNameDefaultDescription
ComplexrootsReal roots
RealnRootsNumber of distinct real solutions expected
Real[3]reReal parts of roots (roots[:].re)
Real[3]imImaginary parts of roots (roots[:].im)