Name | Description |
---|---|
ScaledPolynomial | Polynomial y_scaled=f( (u-u_min)/(u_max - u_min) ) |
Evaluation | Evaluate scaled polynomial with input signal |
value | Evaluate polynomial with Horner's scheme |
newScaledPolynomial | Generate a new ScaledPolynomial record |
The polynomial y = f(u) is defined as du := (u - u_min) / (u_max - u_min); dy := c[1]*du^n + c[2]*du^(n-1) + ... + c[n]*du + c[n+1]; y := y_min + (y_max - y_min)*dy; where u is the abszissa, y is the ordinate and c is the vector of coefficients of the scaled polynomial. As a result, the abszissa du and the ordinate dy of the scaled polynomial p are in the range 0.1. Outside of this range, the polynomial is replaced by the tangents at the u_min and the u_max points of the polynomial.
Name | Default | Description |
---|---|---|
replaceable type uType | Real | Type of abscissa u |
replaceable type yType | Real | Type of ordinate y |
u_min | 0 | Minimum value of u for which polynomial is valid |
u_max | 1 | Maximum value of u for which polynomial is valid |
y_min | 0 | Minimum value of y for which polynomial is valid |
y_max | 1 | Maximum value of y for which polynomial is valid |
c[:] | {1} | Coefficients of polynomial scaled with u_min, u_max, y_min, y_max |
y_umin | Value of y at u_min | |
der_y_umin | First derivative of y at u_min | |
y_umax | Value of y at u_max | |
der_y_umax | First derivative of y at u_max | |
original[:, 2] | Original data from which polynomial has been constructed [u(i), y(i)] pairs (data is not used) |
record ScaledPolynomial "Polynomial y_scaled=f( (u-u_min)/(u_max - u_min) )" replaceable type uType = Real "Type of abscissa u"; replaceable type yType = Real "Type of ordinate y"; parameter uType u_min=0 "Minimum value of u for which polynomial is valid"; parameter uType u_max=1 "Maximum value of u for which polynomial is valid"; parameter yType y_min=0 "Minimum value of y for which polynomial is valid"; parameter yType y_max=1 "Maximum value of y for which polynomial is valid"; parameter Real c[:]={1} "Coefficients of polynomial scaled with u_min, u_max, y_min, y_max"; parameter yType y_umin "Value of y at u_min"; parameter Real der_y_umin "First derivative of y at u_min"; parameter yType y_umax "Value of y at u_max"; parameter Real der_y_umax "First derivative of y at u_max"; parameter Real original[:, 2] "Original data from which polynomial has been constructed [u(i), y(i)] pairs (data is not used)"; end ScaledPolynomial;
This blocks computes the output as polynomial value of the input:
du = (u - u_min)/(u_max - u_min); dy = c[1]*du^n + c[2]*du^(n-1) + ... + c[n]*du + c[n+1]; y = y_min + (y_max - y_min)*dy; where u : input signal (= inPort.signal[1]) y : output signal (= outPort.signal[1]) c[:]: coefficients of scaled polynomial as vector with n+1 elements
If u is smaller as u_min or larger as u_max, the output is the tangent on the polynominal at the corresponding point:
if u < u_min then y = y_umin + der_y_umin*(u - u_min); elseif u > u_max then y = y_umax + der_y_umax*(u - u_max); end if;
Example:
c := {2,3,1}; u := 2 results in y := 2*2^2 + 3*2 + 1 := 15
Name | Default | Description |
---|---|---|
poly | Scaled polynomial |
block Evaluation "Evaluate scaled polynomial with input signal" extends Blocks.Interfaces.SISO; parameter ScaledPolynomial poly "Scaled polynomial"; protected Real du=(u - poly.u_min)/(poly.u_max - poly.u_min); Real dy; Real w[size(poly.c, 1) - 1] "Auxiliary vector"; equation // Evaluate polynomial with Horners scheme [w; dy] = [poly.c] + du*[0; w]; y = if noEvent(u < poly.u_min) then poly.y_umin + poly.der_y_umin*(u - poly. u_min) else if noEvent(u > poly.u_max) then poly.y_umax + poly.der_y_umax*( u - poly.u_max) else poly.y_min + (poly.y_max - poly.y_min)*dy; end Evaluation;
function value "Evaluate polynomial with Horner's scheme" extends Icons.Function; input ScaledPolynomial poly; input Real u "Value at which polynomial poly shall be evaluated"; output Real y "Polynomial value at u"; protected Real du=(u - poly.u_min)/(poly.u_max - poly.u_min); algorithm if u < poly.u_min then y := poly.y_umin + poly.der_y_umin*(u - poly.u_min); elseif u > poly.u_max then y := poly.y_umax + poly.der_y_umax + (u - poly.u_max); else y := poly.c[1]; for j in 2:size(u, 1) loop y := poly.c[j] + du*y; end for; y := poly.y_min + (poly.y_max - poly.y_min)*y; end if; end value;
function newScaledPolynomial "Generate a new ScaledPolynomial record" extends Icons.Function; input Real u_min=0 "Minimum value of u for which polynomial is valid"; input Real u_max=1 "Maximum value of u for which polynomial is valid"; input Real y_min=0 "Minimum value of y for which polynomial is valid"; input Real y_max=1 "Maximum value of y for which polynomial is valid"; input Real c[:]={1} "Coefficients of polynomial scaled with u_min, u_max, y_min, y_max"; input Real y_umin "Value of y at u_min"; input Real der_y_umin "First derivative of y at u_min"; input Real y_umax "Value of y at u_max"; input Real der_y_umax "First derivative of y at u_max"; input Real original[:, 2] "Original data from which polynomial has been constructed [u(i), y(i)] pairs (data is not used)"; output ScaledPolynomial result( u_min=u_min, u_max=u_max, y_min=y_min, y_max=y_max, c=c, y_umin=y_umin, der_y_umin=der_y_umin, y_umax=y_umax, der_y_umax=der_y_umax, original=original); end newScaledPolynomial;