Library of functions operating on polynomials (including polynomial fitting)
This package contains functions to operate on polynomials, in particular to determine the derivative and the integral of a polynomial and to use a polynomial to fit a given set of data points.
Copyright © 2004-2020, Modelica Association and contributors
Extends from Modelica.Icons.FunctionsPackage (Icon for packages containing functions).
Name | Description |
---|---|
evaluate | Evaluate polynomial at a given abscissa value |
evaluateWithRange | Evaluate polynomial at a given abscissa value with linear extrapolation outside of the defined range |
derivative | Derivative of polynomial |
derivativeValue | Value of derivative of polynomial at abscissa value u |
secondDerivativeValue | Value of 2nd derivative of polynomial at abscissa value u |
integral | Indefinite integral of polynomial p(u) |
integralValue | Integral of polynomial p(u) from u_low to u_high |
fitting | Computes the coefficients of a polynomial that fits a set of data points in a least-squares sense |
evaluate_der | Evaluate derivative of polynomial at a given abscissa value |
evaluateWithRange_der | Evaluate derivative of polynomial at a given abscissa value with extrapolation outside of the defined range |
integralValue_der | Time derivative of integral of polynomial p(u) from u_low to u_high, assuming only u_high as time-dependent (Leibniz rule) |
derivativeValue_der | Time derivative of derivative of polynomial |
roots | Compute zeros of a polynomial where the highest coefficient is assumed as not to be zero |
Evaluate polynomial at a given abscissa value
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients (p[1] is coefficient of highest power) |
u | Abscissa value |
Name | Description |
---|---|
y | Value of polynomial at u |
Evaluate polynomial at a given abscissa value with linear extrapolation outside of the defined range
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients (p[1] is coefficient of highest power) |
uMin | Polynomial valid in the range uMin .. uMax |
uMax | Polynomial valid in the range uMin .. uMax |
u | Abscissa value |
Name | Description |
---|---|
y | Value of polynomial at u. Outside of uMin,uMax, linear extrapolation is used |
Derivative of polynomial
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p1[:] | Polynomial coefficients (p1[1] is coefficient of highest power) |
Name | Description |
---|---|
p2[size(p1, 1) - 1] | Derivative of polynomial p1 |
Value of derivative of polynomial at abscissa value u
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients (p[1] is coefficient of highest power) |
u | Abscissa value |
Name | Description |
---|---|
y | Value of derivative of polynomial at u |
Value of 2nd derivative of polynomial at abscissa value u
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients (p[1] is coefficient of highest power) |
u | Abscissa value |
Name | Description |
---|---|
y | Value of 2nd derivative of polynomial at u |
Indefinite integral of polynomial p(u)
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p1[:] | Polynomial coefficients (p1[1] is coefficient of highest power) |
Name | Description |
---|---|
p2[size(p1, 1) + 1] | Polynomial coefficients of indefinite integral of polynomial p1 (polynomial p2 + C is the indefinite integral of p1, where C is an arbitrary constant) |
Integral of polynomial p(u) from u_low to u_high
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients |
u_high | High integrand value |
u_low | Low integrand value, default 0 |
Name | Description |
---|---|
integral | Integral of polynomial p from u_low to u_high |
Computes the coefficients of a polynomial that fits a set of data points in a least-squares sense
Polynomials.fitting(u,y,n) computes the coefficients of a polynomial p(u) of degree "n" that fits the data "p(u[i]) - y[i]" in a least squares sense. The polynomial is returned as a vector p[n+1] that has the following definition:
p(u) = p[1]*u^n + p[2]*u^(n-1) + ... + p[n]*u + p[n+1];
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
u[:] | Abscissa data values |
y[size(u, 1)] | Ordinate data values |
n | Order of desired polynomial that fits the data points (u,y) |
Name | Description |
---|---|
p[n + 1] | Polynomial coefficients of polynomial that fits the date points |
Evaluate derivative of polynomial at a given abscissa value
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients (p[1] is coefficient of highest power) |
u | Abscissa value |
du | Delta of abscissa value |
Name | Description |
---|---|
dy | Value of derivative of polynomial at u |
Evaluate derivative of polynomial at a given abscissa value with extrapolation outside of the defined range
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients (p[1] is coefficient of highest power) |
uMin | Polynomial valid in the range uMin .. uMax |
uMax | Polynomial valid in the range uMin .. uMax |
u | Abscissa value |
du | Delta of abscissa value |
Name | Description |
---|---|
dy | Value of derivative of polynomial at u |
Time derivative of integral of polynomial p(u) from u_low to u_high, assuming only u_high as time-dependent (Leibniz rule)
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients |
u_high | High integrand value |
u_low | Low integrand value, default 0 |
du_high | High integrand value |
du_low | Low integrand value, default 0 |
Name | Description |
---|---|
dintegral | Integral of polynomial p from u_low to u_high |
Time derivative of derivative of polynomial
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Polynomial coefficients (p[1] is coefficient of highest power) |
u | Abscissa value |
du | Delta of abscissa value |
Name | Description |
---|---|
dy | Time-derivative of derivative of polynomial w.r.t. input variable at u |
Compute zeros of a polynomial where the highest coefficient is assumed as not to be zero
r = Polynomials.roots(p);
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.
r = roots({1,2,3}); // r = [-1.0, 1.41421356237309; // -1.0, -1.41421356237309] // which corresponds to the roots: -1.0 +/- j*1.41421356237309
Extends from Modelica.Icons.Function (Icon for functions).
Name | Description |
---|---|
p[:] | Vector with polynomial coefficients p[1]*x^n + p[2]*x^(n-1) + p[n]*x +p[n-1] |
Name | Description |
---|---|
roots[max(0, size(p, 1) - 1), 2] | roots[:,1] and roots[:,2] are the real and imaginary parts of the roots of polynomial p |