Modelica.Media.Incompressible.TableBased.Polynomials_Temp

Temporary Functions operating on polynomials (including polynomial fitting); only to be used in Modelica.Media.Incompressible.TableBased

Information


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).

Package Content

NameDescription
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate evaluate Evaluate polynomial at a given abszissa value
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivative derivative Derivative of polynomial
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivativeValue derivativeValue Value of derivative of polynomial at abszissa value u
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.secondDerivativeValue secondDerivativeValue Value of 2nd derivative of polynomial at abszissa value u
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integral integral Indefinite integral of polynomial p(u)
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integralValue integralValue Integral of polynomial p(u) from u_low to u_high
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.fitting fitting Computes the coefficients of a polynomial that fits a set of data points in a least-squares sense
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate_der evaluate_der Evaluate polynomial at a given abszissa value
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.integralValue_der 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)
Modelica.Media.Incompressible.TableBased.Polynomials_Temp.derivativeValue_der derivativeValue_der time derivative of derivative of polynomial


Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate Modelica.Media.Incompressible.TableBased.Polynomials_Temp.evaluate

Evaluate polynomial at a given abszissa value

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp[:] Polynomial coefficients (p[1] is coefficient of highest power)
Realu Abszissa value

Outputs

TypeNameDescription
RealyValue of polynomial at u

Modelica definition

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

Derivative of polynomial

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp1[:] Polynomial coefficients (p1[1] is coefficient of highest power)

Outputs

TypeNameDescription
Realp2[size(p1, 1) - 1]Derivative of polynomial p1

Modelica definition

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

Value of derivative of polynomial at abszissa value u

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp[:] Polynomial coefficients (p[1] is coefficient of highest power)
Realu Abszissa value

Outputs

TypeNameDescription
RealyValue of derivative of polynomial at u

Modelica definition

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

Value of 2nd derivative of polynomial at abszissa value u

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp[:] Polynomial coefficients (p[1] is coefficient of highest power)
Realu Abszissa value

Outputs

TypeNameDescription
RealyValue of 2nd derivative of polynomial at u

Modelica definition

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

Indefinite integral of polynomial p(u)

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp1[:] Polynomial coefficients (p1[1] is coefficient of highest power)

Outputs

TypeNameDescription
Realp2[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)

Modelica definition

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

Integral of polynomial p(u) from u_low to u_high

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp[:] Polynomial coefficients
Realu_high High integrand value
Realu_low0Low integrand value, default 0

Outputs

TypeNameDescription
RealintegralIntegral of polynomial p from u_low to u_high

Modelica definition

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

Computes the coefficients of a polynomial that fits a set of data points in a least-squares sense

Information


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).

Inputs

TypeNameDefaultDescription
Realu[:] Abscissa data values
Realy[size(u, 1)] Ordinate data values
Integern Order of desired polynomial that fits the data points (u,y)

Outputs

TypeNameDescription
Realp[n + 1]Polynomial coefficients of polynomial that fits the date points

Modelica definition

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

Evaluate polynomial at a given abszissa value

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp[:] Polynomial coefficients (p[1] is coefficient of highest power)
Realu Abszissa value
Realdu Abszissa value

Outputs

TypeNameDescription
RealdyValue of polynomial at u

Modelica definition

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

Time derivative of integral of polynomial p(u) from u_low to u_high, assuming only u_high as time-dependent (Leibnitz rule)

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp[:] Polynomial coefficients
Realu_high High integrand value
Realu_low0Low integrand value, default 0
Realdu_high High integrand value
Realdu_low0Low integrand value, default 0

Outputs

TypeNameDescription
RealdintegralIntegral of polynomial p from u_low to u_high

Modelica definition

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

time derivative of derivative of polynomial

Information

Extends from Modelica.Icons.Function (Icon for a function).

Inputs

TypeNameDefaultDescription
Realp[:] Polynomial coefficients (p[1] is coefficient of highest power)
Realu Abszissa value
Realdu delta of abszissa value

Outputs

TypeNameDescription
Realdytime-derivative of derivative of polynomial w.r.t. input variable at u

Modelica definition

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;

HTML-documentation generated by Dymola Sun Jan 17 21:12:29 2010.