result = Polynomial.roots(p, printRoots);
The roots of the given polynomial p
are determined
and are returned as a vector of Complex elements.
If the optional argument printRoots
is set to true, the roots are also printed at once.
import Modelica_LinearSystems2.Math.Polynomial; x = Polynomial.x(); p1 = -6*x^2 + 4*x -3; Polynomial.roots(p1); // {0.333333 + 0.62361*j, 0.333333 - 0.62361*j} Polynomial.roots(p1, true); // = // 0.333333 + 0.62361*j // 0.333333 - 0.62361*j // {0.333333 + 0.62361*j, 0.333333 - 0.62361*j}
encapsulated function roots import Complex; import Modelica_LinearSystems2.ComplexMathAdds.Vectors; import Modelica_LinearSystems2.Math.Polynomial; input Polynomial p "Polynomial"; input Boolean printRoots = false "True, if roots shall be pretty printed"; output Complex result[:] = fill(Complex(0, 0), Polynomial.numberOfRoots(p)) "Roots of polynomial"; end roots;