## Modelica.Math

Mathematical functions

### Information

This package contains the following basic mathematical functions:

       sin(u)        sine
       cos(u)        cosine
       tan(u)        tangent     (u shall not be -pi/2, pi/2, 3*pi/2, ...)
       asin(u)       inverse sine    (-1 <= u <= 1)
       acos(u)       inverse cosine  (-1 <= u <= 1)
       atan(u)       inverse tangent
       atan2(u1,u2)  four quadrant inverse tangent
       sinh(u)       hyperbolic sine
       cosh(u)       hyperbolic cosine
       tanh(u)       hyperbolic tangent
       exp(u)        exponential, base e
       log(u)        natural (base e) logarithm (u > 0)
       log10(u)      base 10 logarithm (u > 0)

These functions are used by calling them directly with a full name (e.g. y = Modelica.Math.asin(0.5)).

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

Release Notes:

- October 21, 2002 by Martin Otter and Christian Schweiger:
  Function tempInterpol2 added.
- Oct. 24, 1999 by Martin Otter:
  Icons for icon and diagram level introduced.
- June 30, 1999 by Martin Otter:
  Realized.

Copyright © 1999-2002, Modelica Association and DLR.

The 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 in the documentation of package Modelica in file "Modelica/package.mo".

## Modelica.Math.baseIcon1

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

### Modelica definition

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

## Modelica.Math.baseIcon2

Basic icon for mathematical function with y-axis in middle

### Modelica definition

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

## Modelica.Math.sin

sine

### Modelica definition

    function sin "sine"
      extends baseIcon1;
      input SI.Angle u;
      output Real y;
    external "C" y = sin(u);
    end sin;

## Modelica.Math.cos

cosine

### Modelica definition

    function cos "cosine"
      extends baseIcon1;
      input SI.Angle u;
      output Real y;
    external "C" y = cos(u);
    end cos;

## Modelica.Math.tan

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

### 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

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

### 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

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

### 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

inverse tangent

### 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

four quadrant inverse tangent

### Information

y = atan2(u1,u2) computes y such that tan(y) = u1/u2 and y is in the range -pi < y < pi. u2 may be zero, provided u1 is not zero.

### 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.sinh

hyperbolic sine

### Modelica definition

    function sinh "hyperbolic sine"
      extends baseIcon2;
      input Real u;
      output Real y;
    external "C" y = sinh(u);
    end sinh;

## Modelica.Math.cosh

hyperbolic cosine

### Modelica definition

    function cosh "hyperbolic cosine"
      extends baseIcon2;
      input Real u;
      output Real y;
    external "C" y = cosh(u);
    end cosh;

## Modelica.Math.tanh

hyperbolic tangent

### Modelica definition

    function tanh "hyperbolic tangent"
      extends baseIcon2;
      input Real u;
      output Real y;
    external "C" y = tanh(u);
    end tanh;

## Modelica.Math.exp

exponential, base e

### 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

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

### 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

base 10 logarithm (u shall be > 0)

### 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.tempInterpol1

temporary routine for linear interpolation (will be removed)

### Modelica definition

    function tempInterpol1
      "temporary routine 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 routine for vectorized linear interpolation (will be removed)

### Modelica definition

    function tempInterpol2
      "temporary routine 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;