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-2009, Modelica Association and DLR.
This package is free software. It can be redistributed and/or modified under the terms of the Modelica license, see the license conditions and the accompanying disclaimer in the documentation of package Modelica in file "Modelica/package.mo".
Extends from Modelica.Icons.Library (Icon for library).
| Name | Description | 
|---|---|
|  evaluate | Evaluate polynomial at a given abszissa value | 
|  derivative | Derivative of polynomial | 
|  derivativeValue | Value of derivative of polynomial at abszissa value u | 
|  secondDerivativeValue | Value of 2nd derivative of polynomial at abszissa 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 polynomial at a given abszissa value | 
|  integralValue_der | Time derivative of integral of polynomial p(u) from u_low to u_high, assuming only u_high as time-dependent (Leibnitz rule) | 
|  derivativeValue_der | time derivative of derivative of polynomial | 
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p[:] | Polynomial coefficients (p[1] is coefficient of highest power) | |
| Real | u | Abszissa value | 
| Type | Name | Description | 
|---|---|---|
| Real | y | Value of polynomial at u | 
function evaluate "Evaluate polynomial at a given abszissa value"
  annotation(derivative=evaluate_der);
  extends Modelica.Icons.Function;
  input Real p[:] 
    "Polynomial coefficients (p[1] is coefficient of highest power)";
  input Real u "Abszissa value";
  output Real y "Value of polynomial at u";
algorithm 
  y := p[1];
  for j in 2:size(p, 1) loop
    y := p[j] + u*y;
  end for;
end evaluate;
 
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivative
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivative
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p1[:] | Polynomial coefficients (p1[1] is coefficient of highest power) | 
| Type | Name | Description | 
|---|---|---|
| Real | p2[size(p1, 1) - 1] | Derivative of polynomial p1 | 
function derivative "Derivative of polynomial"
  extends Modelica.Icons.Function;
  input Real p1[:] 
    "Polynomial coefficients (p1[1] is coefficient of highest power)";
  output Real p2[size(p1, 1) - 1] "Derivative of polynomial p1";
protected 
  Integer n=size(p1, 1);
algorithm 
  for j in 1:n-1 loop
    p2[j] := p1[j]*(n - j);
  end for;
end derivative;
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivativeValue
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivativeValue
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p[:] | Polynomial coefficients (p[1] is coefficient of highest power) | |
| Real | u | Abszissa value | 
| Type | Name | Description | 
|---|---|---|
| Real | y | Value of derivative of polynomial at u | 
function derivativeValue 
  "Value of derivative of polynomial at abszissa value u"
  annotation(derivative=derivativeValue_der);
  extends Modelica.Icons.Function;
  input Real p[:] 
    "Polynomial coefficients (p[1] is coefficient of highest power)";
  input Real u "Abszissa value";
  output Real y "Value of derivative of polynomial at u";
protected 
  Integer n=size(p, 1);
algorithm 
  y := p[1]*(n - 1);
  for j in 2:size(p, 1)-1 loop
    y := p[j]*(n - j) + u*y;
  end for;
end derivativeValue;
 
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.secondDerivativeValue
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.secondDerivativeValue
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p[:] | Polynomial coefficients (p[1] is coefficient of highest power) | |
| Real | u | Abszissa value | 
| Type | Name | Description | 
|---|---|---|
| Real | y | Value of 2nd derivative of polynomial at u | 
function secondDerivativeValue 
  "Value of 2nd derivative of polynomial at abszissa value u"
  extends Modelica.Icons.Function;
  input Real p[:] 
    "Polynomial coefficients (p[1] is coefficient of highest power)";
  input Real u "Abszissa value";
  output Real y "Value of 2nd derivative of polynomial at u";
protected 
  Integer n=size(p, 1);
algorithm 
  y := p[1]*(n - 1)*(n - 2);
  for j in 2:size(p, 1)-2 loop
    y := p[j]*(n - j)*(n - j - 1) + u*y;
  end for;
end secondDerivativeValue;
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integral
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integral
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p1[:] | Polynomial coefficients (p1[1] is coefficient of highest power) | 
| Type | Name | Description | 
|---|---|---|
| Real | 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) | 
function integral "Indefinite integral of polynomial p(u)"
  extends Modelica.Icons.Function;
  input Real p1[:] 
    "Polynomial coefficients (p1[1] is coefficient of highest power)";
  output Real 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)";
protected 
  Integer n=size(p1, 1) + 1 "degree of output polynomial";
algorithm 
  for j in 1:n-1 loop
    p2[j] := p1[j]/(n-j);
  end for;
end integral;
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integralValue
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integralValue
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p[:] | Polynomial coefficients | |
| Real | u_high | High integrand value | |
| Real | u_low | 0 | Low integrand value, default 0 | 
| Type | Name | Description | 
|---|---|---|
| Real | integral | Integral of polynomial p from u_low to u_high | 
function integralValue 
  "Integral of polynomial p(u) from u_low to u_high"
  annotation(derivative=integralValue_der);
  extends Modelica.Icons.Function;
  input Real p[:] "Polynomial coefficients";
  input Real u_high "High integrand value";
  input Real u_low=0 "Low integrand value, default 0";
  output Real integral=0.0 "Integral of polynomial p from u_low to u_high";
protected 
  Integer n=size(p, 1) "degree of integrated polynomial";
  Real y_low=0 "value at lower integrand";
algorithm 
  for j in 1:n loop
    integral := u_high*(p[j]/(n - j + 1) + integral);
    y_low := u_low*(p[j]/(n - j + 1) + y_low);
  end for;
  integral := integral - y_low;
end integralValue;
 
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.fitting
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.fitting
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 a function).
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | u[:] | Abscissa data values | |
| Real | y[size(u, 1)] | Ordinate data values | |
| Integer | n | Order of desired polynomial that fits the data points (u,y) | 
| Type | Name | Description | 
|---|---|---|
| Real | p[n + 1] | Polynomial coefficients of polynomial that fits the date points | 
function fitting 
  "Computes the coefficients of a polynomial that fits a set of data points in a least-squares sense"
  extends Modelica.Icons.Function;
  input Real u[:] "Abscissa data values";
  input Real y[size(u, 1)] "Ordinate data values";
  input Integer n(min=1) 
    "Order of desired polynomial that fits the data points (u,y)";
  output Real p[n + 1] 
    "Polynomial coefficients of polynomial that fits the date points";
protected 
  Real V[size(u, 1), n + 1] "Vandermonde matrix";
algorithm 
  // Construct Vandermonde matrix
  V[:, n + 1] := ones(size(u, 1));
  for j in n:-1:1 loop
    V[:, j] := {u[i] * V[i, j + 1] for i in 1:size(u,1)};
  end for;
  // Solve least squares problem
  p :=Modelica.Math.Matrices.leastSquares(V, y);
end fitting;
 
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate_der
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate_der
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p[:] | Polynomial coefficients (p[1] is coefficient of highest power) | |
| Real | u | Abszissa value | |
| Real | du | Abszissa value | 
| Type | Name | Description | 
|---|---|---|
| Real | dy | Value of polynomial at u | 
function evaluate_der "Evaluate polynomial at a given abszissa value"
  extends Modelica.Icons.Function;
  input Real p[:] 
    "Polynomial coefficients (p[1] is coefficient of highest power)";
  input Real u "Abszissa value";
  input Real du "Abszissa value";
  output Real dy "Value of polynomial at u";
protected 
  Integer n=size(p, 1);
algorithm 
  dy := p[1]*(n - 1);
  for j in 2:size(p, 1)-1 loop
    dy := p[j]*(n - j) + u*dy;
  end for;
  dy := dy*du;
end evaluate_der;
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integralValue_der
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integralValue_der
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p[:] | Polynomial coefficients | |
| Real | u_high | High integrand value | |
| Real | u_low | 0 | Low integrand value, default 0 | 
| Real | du_high | High integrand value | |
| Real | du_low | 0 | Low integrand value, default 0 | 
| Type | Name | Description | 
|---|---|---|
| Real | dintegral | Integral of polynomial p from u_low to u_high | 
function integralValue_der "Time derivative of integral of polynomial p(u) from u_low to u_high, assuming only u_high as time-dependent (Leibnitz rule)" extends Modelica.Icons.Function; input Real p[:] "Polynomial coefficients"; input Real u_high "High integrand value"; input Real u_low=0 "Low integrand value, default 0"; input Real du_high "High integrand value"; input Real du_low=0 "Low integrand value, default 0"; output Real dintegral=0.0 "Integral of polynomial p from u_low to u_high"; algorithm dintegral := evaluate(p,u_high)*du_high; end integralValue_der;
 Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivativeValue_der
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivativeValue_der
| Type | Name | Default | Description | 
|---|---|---|---|
| Real | p[:] | Polynomial coefficients (p[1] is coefficient of highest power) | |
| Real | u | Abszissa value | |
| Real | du | delta of abszissa value | 
| Type | Name | Description | 
|---|---|---|
| Real | dy | time-derivative of derivative of polynomial w.r.t. input variable at u | 
function derivativeValue_der 
  "time derivative of derivative of polynomial"
  extends Modelica.Icons.Function;
  input Real p[:] 
    "Polynomial coefficients (p[1] is coefficient of highest power)";
  input Real u "Abszissa value";
  input Real du "delta of abszissa value";
  output Real dy 
    "time-derivative of derivative of polynomial w.r.t. input variable at u";
protected 
  Integer n=size(p, 1);
algorithm 
  dy := secondDerivativeValue(p,u)*du;
end derivativeValue_der;