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 and matrices.

Main Author:
Martin Otter
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-2009, Modelica Association and DLR.

This Modelica 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 here.


Extends from Modelica.Icons.Library2 (Icon for library where additional icon elements shall be added).

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.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 tangens (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.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 SI.Angle u;
  output Real y;

external "C" 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 "C" 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 "C" 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 "C" 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 "C" 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 "C" 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 "C" y = atan2(u1, u2);
end atan2;

Modelica.Math.atan3 Modelica.Math.atan3

Four quadrant inverse tangens (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 tangens (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 "C" 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 "C" 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 "C" 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 "C" 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 "C" 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 "C" 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

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;

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