Modelica.Math

Library of mathematical functions (e.g., sin, cos) and of functions operating on vectors and matrices

Information


This package contains basic mathematical functions (such as sin(..)), as well as functions operating on vectors, matrices, nonlinear functions, and Boolean vectors.

Main Authors:
Martin Otter and Marcus Baur
Deutsches Zentrum für Luft und Raumfahrt e.V. (DLR)
Institut für Robotik und Mechatronik
Postfach 1116
D-82230 Wessling
Germany
email: Martin.Otter@dlr.de

Copyright © 1998-2010, Modelica Association and DLR.

This Modelica package is free software and the use is completely at your own risk; it can be redistributed and/or modified under the terms of the Modelica License 2. For license conditions (including the disclaimer of warranty) see Modelica.UsersGuide.ModelicaLicense2 or visit http://www.modelica.org/licenses/ModelicaLicense2.

Extends from Modelica.Icons.Package (Icon for standard packages).

Package Content

NameDescription
Modelica.Math.Vectors Vectors Library of functions operating on vectors
Modelica.Math.Matrices Matrices Library of functions operating on matrices
Modelica.Math.Nonlinear Nonlinear Library of functions operating on nonlinear equations
Modelica.Math.BooleanVectors BooleanVectors Library of functions operating on Boolean vectors
Modelica.Math.isEqual isEqual Determine if two Real scalars are numerically identical
Modelica.Math.sin sin Sine
Modelica.Math.cos cos Cosine
Modelica.Math.tan tan Tangent (u shall not be -pi/2, pi/2, 3*pi/2, ...)
Modelica.Math.asin asin Inverse sine (-1 <= u <= 1)
Modelica.Math.acos acos Inverse cosine (-1 <= u <= 1)
Modelica.Math.atan atan Inverse tangent
Modelica.Math.atan2 atan2 Four quadrant inverse tangent
Modelica.Math.atan3 atan3 Four quadrant inverse tangent (select solution that is closest to given angle y0)
Modelica.Math.sinh sinh Hyperbolic sine
Modelica.Math.cosh cosh Hyperbolic cosine
Modelica.Math.tanh tanh Hyperbolic tangent
Modelica.Math.asinh asinh Inverse of sinh (area hyperbolic sine)
Modelica.Math.acosh acosh Inverse of cosh (area hyperbolic cosine)
Modelica.Math.exp exp Exponential, base e
Modelica.Math.log log Natural (base e) logarithm (u shall be > 0)
Modelica.Math.log10 log10 Base 10 logarithm (u shall be > 0)
Modelica.Math.baseIcon1 baseIcon1 Basic icon for mathematical function with y-axis on left side
Modelica.Math.baseIcon2 baseIcon2 Basic icon for mathematical function with y-axis in middle
Modelica.Math.tempInterpol1 tempInterpol1 Temporary function for linear interpolation (will be removed)
Modelica.Math.tempInterpol2 tempInterpol2 Temporary function for vectorized linear interpolation (will be removed)


Modelica.Math.isEqual Modelica.Math.isEqual

Determine if two Real scalars are numerically identical

Information


Syntax

Math.isEqual(s1, s2);
Math.isEqual(s1, s2, eps=0);

Description

The function call "Math.isEqual(s1, s2)" returns true, if the two Real scalars s1 and s2 are identical. Otherwise the function returns false. The equality check is performed by "abs(s1-s2) ≤ eps", where "eps" can be provided as third argument of the function. Default is "eps = 0".

Example

  Real s1 = 2.0;
  Real s2 = 2.0;
  Real s3 = 2.000001;
  Boolean result;
algorithm
  result := Math.isEqual(s1,s2);     // = true
  result := Math.isEqual(s1,s3);     // = false
  result := Math.isEqual(s1,s3,0.1); // = true

See also

Vectors.isEqual, Matrices.isEqual, Strings.isEqual

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
Reals1 First scalar
Reals2 Second scalar
Realeps0The two scalars are identical if abs(s1-s2) <= eps

Outputs

TypeNameDescription
Booleanresult= true, if scalars are identical

Modelica definition

function isEqual 
  "Determine if two Real scalars are numerically identical"
  extends Modelica.Icons.Function;
  input Real s1 "First scalar";
  input Real s2 "Second scalar";
  input Real eps(min=0) = 0 
    "The two scalars are identical if abs(s1-s2) <= eps";
  output Boolean result "= true, if scalars are identical";
algorithm 
  result :=abs(s1 - s2) <= eps;
end isEqual;

Modelica.Math.sin Modelica.Math.sin

Sine

Modelica.Math.sin

Information


This function returns y = sin(u), with -∞ < u < ∞:

Extends from baseIcon1 (Basic icon for mathematical function with y-axis on left side).

Inputs

TypeNameDefaultDescription
Angleu [rad]

Outputs

TypeNameDescription
Realy 

Modelica definition

function sin "Sine"
  extends baseIcon1;
  input Modelica.SIunits.Angle u;
  output Real y;

external "builtin" y = sin(u);
end sin;

Modelica.Math.cos Modelica.Math.cos

Cosine

Modelica.Math.cos

Information


This function returns y = cos(u), with -∞ < u < ∞:

Extends from baseIcon1 (Basic icon for mathematical function with y-axis on left side).

Inputs

TypeNameDefaultDescription
Angleu [rad]

Outputs

TypeNameDescription
Realy 

Modelica definition

function cos "Cosine"
  extends baseIcon1;
  input SI.Angle u;
  output Real y;

external "builtin" y = cos(u);
end cos;

Modelica.Math.tan Modelica.Math.tan

Tangent (u shall not be -pi/2, pi/2, 3*pi/2, ...)

Modelica.Math.tan

Information


This function returns y = tan(u), with -∞ < u < ∞ (if u is a multiple of (2n-1)*pi/2, y = tan(u) is +/- infinity).

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Angleu [rad]

Outputs

TypeNameDescription
Realy 

Modelica definition

function tan "Tangent (u shall not be -pi/2, pi/2, 3*pi/2, ...)"
  extends baseIcon2;
  input SI.Angle u;
  output Real y;

external "builtin" y = tan(u);
end tan;

Modelica.Math.asin Modelica.Math.asin

Inverse sine (-1 <= u <= 1)

Modelica.Math.asin

Information


This function returns y = asin(u), with -1 ≤ u ≤ +1:

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Angley[rad]

Modelica definition

function asin "Inverse sine (-1 <= u <= 1)"
  extends baseIcon2;
  input Real u;
  output SI.Angle y;

external "builtin" y = asin(u);
end asin;

Modelica.Math.acos Modelica.Math.acos

Inverse cosine (-1 <= u <= 1)

Modelica.Math.acos

Information


This function returns y = acos(u), with -1 ≤ u ≤ +1:

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Angley[rad]

Modelica definition

function acos "Inverse cosine (-1 <= u <= 1)"
  extends baseIcon2;
  input Real u;
  output SI.Angle y;

external "builtin" y = acos(u);
end acos;

Modelica.Math.atan Modelica.Math.atan

Inverse tangent

Modelica.Math.atan

Information


This function returns y = atan(u), with -∞ < u < ∞:

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Angley[rad]

Modelica definition

function atan "Inverse tangent"
  extends baseIcon2;
  input Real u;
  output SI.Angle y;

external "builtin" y = atan(u);
end atan;

Modelica.Math.atan2 Modelica.Math.atan2

Four quadrant inverse tangent

Modelica.Math.atan2

Information


This function returns y = atan2(u1,u2) such that tan(y) = u1/u2 and
y is in the range -pi < y ≤ pi. u2 may be zero, provided
u1 is not zero. Usually u1, u2 is provided in such a form that
u1 = sin(y) and u2 = cos(y):

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu1  
Realu2  

Outputs

TypeNameDescription
Angley[rad]

Modelica definition

function atan2 "Four quadrant inverse tangent"
  extends baseIcon2;
  input Real u1;
  input Real u2;
  output SI.Angle y;

external "builtin" y = atan2(u1, u2);
end atan2;

Modelica.Math.atan3 Modelica.Math.atan3

Four quadrant inverse tangent (select solution that is closest to given angle y0)

Modelica.Math.atan3

Information


This function returns y = atan3(u1,u2,y0) such that tan(y) = u1/u2 and y is in the range: -pi < y-y0 < pi.
u2 may be zero, provided u1 is not zero. The difference to Modelica.Math.atan2(..) is the optional third argument y0 that allows to specify which of the infinite many solutions shall be returned:

Extends from Modelica.Math.baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu1  
Realu2  
Angley00y shall be in the range: -pi < y-y0 < pi [rad]

Outputs

TypeNameDescription
Angley[rad]

Modelica definition

function atan3 
  "Four quadrant inverse tangent (select solution that is closest to given angle y0)"
  import Modelica.Math;
  extends Modelica.Math.baseIcon2;
  input Real u1;
  input Real u2;
  input Modelica.SIunits.Angle y0=0 "y shall be in the range: -pi < y-y0 < pi";
  output Modelica.SIunits.Angle y;

protected 
  Real pi = Modelica.Constants.pi;
  Real w;
algorithm 
  w :=Math.atan2(u1, u2);
  y := w + 2*pi*div(abs(w-y0)+pi,2*pi)*(if y0 > w then +1 else -1);
end atan3;

Modelica.Math.sinh Modelica.Math.sinh

Hyperbolic sine

Modelica.Math.sinh

Information


This function returns y = sinh(u), with -∞ < u < ∞:

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function sinh "Hyperbolic sine"
  extends baseIcon2;
  input Real u;
  output Real y;

external "builtin" y = sinh(u);
end sinh;

Modelica.Math.cosh Modelica.Math.cosh

Hyperbolic cosine

Modelica.Math.cosh

Information


This function returns y = cosh(u), with -∞ < u < ∞:

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function cosh "Hyperbolic cosine"
  extends baseIcon2;
  input Real u;
  output Real y;

external "builtin" y = cosh(u);
end cosh;

Modelica.Math.tanh Modelica.Math.tanh

Hyperbolic tangent

Modelica.Math.tanh

Information


This function returns y = tanh(u), with -∞ < u < ∞:

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function tanh "Hyperbolic tangent"
  extends baseIcon2;
  input Real u;
  output Real y;

external "builtin" y = tanh(u);
end tanh;

Modelica.Math.asinh Modelica.Math.asinh

Inverse of sinh (area hyperbolic sine)

Modelica.Math.asinh

Information


The function returns the area hyperbolic sine of its input argument u. This inverse of sinh(..) is unique and there is no restriction on the input argument u of asinh(u) (-∞ < u < ∞):

Extends from Modelica.Math.baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function asinh "Inverse of sinh (area hyperbolic sine)"
  extends Modelica.Math.baseIcon2;
  input Real u;
  output Real y;

algorithm 
  y :=Modelica.Math.log(u + sqrt(u*u + 1));
end asinh;

Modelica.Math.acosh Modelica.Math.acosh

Inverse of cosh (area hyperbolic cosine)

Modelica.Math.acosh

Information


This function returns the area hyperbolic cosine of its input argument u. The valid range of u is

  +1 ≤ u < +∞

If the function is called with u < 1, an error occurs. The function cosh(u) has two inverse functions (the curve looks similar to a sqrt(..) function). acosh(..) returns the inverse that is positive. At u=1, the derivative dy/du is infinite. Therefore, this function should not be used in a model, if u can become close to 1:

Extends from Modelica.Math.baseIcon1 (Basic icon for mathematical function with y-axis on left side).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function acosh "Inverse of cosh (area hyperbolic cosine)"
  import Modelica.Utilities.Streams.*;
  extends Modelica.Math.baseIcon1;
  input Real u;
  output Real y;

algorithm 
  assert(u>=1.0, "Input argument u (= " + String(u) + ") of acosh(u) must be >= 1.0");
  y :=Modelica.Math.log(u + sqrt(u*u - 1));
end acosh;

Modelica.Math.exp Modelica.Math.exp

Exponential, base e

Modelica.Math.exp

Information


This function returns y = exp(u), with -∞ < u < ∞:

Extends from baseIcon2 (Basic icon for mathematical function with y-axis in middle).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function exp "Exponential, base e"
  extends baseIcon2;
  input Real u;
  output Real y;

external "builtin" y = exp(u);
end exp;

Modelica.Math.log Modelica.Math.log

Natural (base e) logarithm (u shall be > 0)

Modelica.Math.log

Information


This function returns y = log(10) (the natural logarithm of u), with u > 0:

Extends from baseIcon1 (Basic icon for mathematical function with y-axis on left side).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function log "Natural (base e) logarithm (u shall be > 0)"
  extends baseIcon1;
  input Real u;
  output Real y;

external "builtin" y = log(u);
end log;

Modelica.Math.log10 Modelica.Math.log10

Base 10 logarithm (u shall be > 0)

Modelica.Math.log10

Information


This function returns y = log10(u), with u > 0:

Extends from baseIcon1 (Basic icon for mathematical function with y-axis on left side).

Inputs

TypeNameDefaultDescription
Realu  

Outputs

TypeNameDescription
Realy 

Modelica definition

function log10 "Base 10 logarithm (u shall be > 0)"
  extends baseIcon1;
  input Real u;
  output Real y;

external "builtin" y = log10(u);
end log10;

Modelica.Math.baseIcon1 Modelica.Math.baseIcon1

Basic icon for mathematical function with y-axis on left side

Modelica.Math.baseIcon1

Information


Icon for a mathematical function, consisting of an y-axis on the left side. It is expected, that an x-axis is added and a plot of the function.

Modelica definition

partial function baseIcon1 
  "Basic icon for mathematical function with y-axis on left side"

end baseIcon1;

Modelica.Math.baseIcon2 Modelica.Math.baseIcon2

Basic icon for mathematical function with y-axis in middle

Modelica.Math.baseIcon2

Information


Icon for a mathematical function, consisting of an y-axis in the middle. It is expected, that an x-axis is added and a plot of the function.

Modelica definition

partial function baseIcon2 
  "Basic icon for mathematical function with y-axis in middle"

end baseIcon2;

Modelica.Math.tempInterpol1

Temporary function for linear interpolation (will be removed)

Information



Inputs

TypeNameDefaultDescription
Realu input value (first column of table)
Realtable[:, :] table to be interpolated
Integericol column of table to be interpolated

Outputs

TypeNameDescription
Realyinterpolated input value (icol column of table)

Modelica definition

function tempInterpol1 
  "Temporary function for linear interpolation (will be removed)"
  input Real u "input value (first column of table)";
  input Real table[:, :] "table to be interpolated";
  input Integer icol "column of table to be interpolated";
  output Real y "interpolated input value (icol column of table)";
protected 
  Integer i;
  Integer n "number of rows of table";
  Real u1;
  Real u2;
  Real y1;
  Real y2;
algorithm 
  n := size(table, 1);

  if n <= 1 then
    y := table[1, icol];

  else
    // Search interval

    if u <= table[1, 1] then
      i := 1;

    else
      i := 2;
      // Supports duplicate table[i, 1] values
      // in the interior to allow discontinuities.
      // Interior means that
      // if table[i, 1] = table[i+1, 1] we require i>1 and i+1<n

      while i < n and u >= table[i, 1] loop
        i := i + 1;

      end while;
      i := i - 1;

    end if;

    // Get interpolation data
    u1 := table[i, 1];
    u2 := table[i + 1, 1];
    y1 := table[i, icol];
    y2 := table[i + 1, icol];

    assert(u2 > u1, "Table index must be increasing");
    // Interpolate
    y := y1 + (y2 - y1)*(u - u1)/(u2 - u1);

  end if;

end tempInterpol1;

Modelica.Math.tempInterpol2

Temporary function for vectorized linear interpolation (will be removed)

Information



Inputs

TypeNameDefaultDescription
Realu input value (first column of table)
Realtable[:, :] table to be interpolated
Integericol[:] column(s) of table to be interpolated

Outputs

TypeNameDescription
Realy[1, size(icol, 1)]interpolated input value(s) (column(s) icol of table)

Modelica definition

function tempInterpol2 
  "Temporary function for vectorized linear interpolation (will be removed)"

  input Real u "input value (first column of table)";
  input Real table[:, :] "table to be interpolated";
  input Integer icol[:] "column(s) of table to be interpolated";
  output Real y[1, size(icol, 1)] 
    "interpolated input value(s) (column(s) icol of table)";
protected 
  Integer i;
  Integer n "number of rows of table";
  Real u1;
  Real u2;
  Real y1[1, size(icol, 1)];
  Real y2[1, size(icol, 1)];
algorithm 
  n := size(table, 1);

  if n <= 1 then
    y := transpose([table[1, icol]]);

  else
    // Search interval

    if u <= table[1, 1] then
      i := 1;

    else
      i := 2;
      // Supports duplicate table[i, 1] values
      // in the interior to allow discontinuities.
      // Interior means that
      // if table[i, 1] = table[i+1, 1] we require i>1 and i+1<n

      while i < n and u >= table[i, 1] loop
        i := i + 1;

      end while;
      i := i - 1;

    end if;

    // Get interpolation data
    u1 := table[i, 1];
    u2 := table[i + 1, 1];
    y1 := transpose([table[i, icol]]);
    y2 := transpose([table[i + 1, icol]]);

    assert(u2 > u1, "Table index must be increasing");
    // Interpolate
    y := y1 + (y2 - y1)*(u - u1)/(u2 - u1);

  end if;

end tempInterpol2;

Automatically generated Fri Nov 12 16:31:48 2010.