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
| Type | Name | Default | Description |
|---|---|---|---|
| Real | a | ||
| Real | b | ||
| Real | c | ||
| Real | d |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | roots | Real roots | |
| Real | nRoots | Number of distinct real solutions expected | |
| Real[3] | re | Real parts of roots (roots[:].re) | |
| Real[3] | im | Imaginary parts of roots (roots[:].im) |