functionroots
Compute zeros of a polynomial where the highest coefficient is assumed as not to be zero
Extends from Modelica.Icons.Function (Icon for functions).
Information
Syntax
r = Polynomials.roots(p);
Description
This function computes the roots of a polynomial P of x
P = p[1]*x^n + p[2]*x^(n-1) + ... + p[n-1]*x + p[n+1];
with the coefficient vector p. It is assumed that the first element of p is not zero, i.e., that the polynomial is of order size(p,1)-1.
To compute the roots, the eigenvalues of the corresponding companion matrix C
|-p[2]/p[1] -p[3]/p[1] ... -p[n-2]/p[1] -p[n-1]/p[1] -p[n]/p[1] |
| 1 0 0 0 0 |
| 0 1 ... 0 0 0 |
C = | . . ... . . . |
| . . ... . . . |
| 0 0 ... 0 1 0 |
are calculated. These are the roots of the polynomial.
Since the companion matrix has already Hessenberg form, the transformation to Hessenberg form has not to be performed.
Function eigenvaluesHessenberg
provides efficient eigenvalue computation for those matrices.
Example
r = roots({1,2,3});
// r = [-1.0, 1.41421356237309;
// -1.0, -1.41421356237309]
// which corresponds to the roots: -1.0 +/- j*1.41421356237309
Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real[:] | p | Vector with polynomial coefficients p[1]*x^n + p[2]*x^(n-1) + p[n]*x +p[n-1] |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real[max(0, size(p, 1) - 1),2] | roots | fill(0, max(0, size(p, 1) - 1), 2) | roots[:,1] and roots[:,2] are the real and imaginary parts of the roots of polynomial p |