## Modelica_LinearSystems2.Math

Additional functions for Modelica.Math

### Information

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

### Package Content

Name | Description
--- | ---
Complex | Record defining a Complex number
Polynomial | Record defining the data for a polynomial
Matrices | Additional functions for Modelica.Math
Vectors | Functions operating on vectors
isEqual | Determine whether two Real numbers are numerically identical (up to machine precision)

## Modelica_LinearSystems2.Math.Complex

Record defining a Complex number

### Information

This record defines a complex number consisting of a real and an imaginary part. Additionally, various utility functions are provided in the record to operate on instances of this record. Example (note: "j" in the comments is defined as j=sqrt(-1)):

       import Modelica.Utilities.Streams;
       import Modelica_LinearSystems2.Math.Complex;
       Complex c1=Complex(re=2, im=3) "= 2 + 3j";
       Complex c2=Complex(3,4) "= 3 + 4j";
     algorithm
       c3 := Complex.'+'(c1, c2) "= c1 + c2";
       Streams.print("c3 = " + Complex.'String'(c3));
       Streams.print("c3 = " + Complex.'String'(c3,"i"));
       // This gives the following print-out:
       c3 = 5 + 7j
       c3 = 5 + 7i

The utility functions are written in such a way that it is convenient to work with them, once operator overloading is provided in Modelica and Modelica tools. Example:

       // Assume operator overloading is available (this is not yet the case):
       Complex j  = Complex.j();
       Complex c4 = -2 + 5*j;
       // A Modelica tool will transform the statement of c4 into
       Complex c4 = Complex.'+'( Complex.(-2,0), Complex.'*'(Complex(5,0),j)));

The utility functions are implemented so that they can be easily inlined by a tool. In such a case, the above statement will not lead to any overhead.

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
re | Real part of complex number
im | Imaginary part of complex number

## Modelica_LinearSystems2.Math.Polynomial

Record defining the data for a polynomial

### Information

This record defines a polynomial, e.g., y = 2*x^2 + 3*x + 1. The general form is:

       y = c[1]*x^n + c[2]*x^(n-1) + ... + c[n]*x + c[n+1];

In the record, the coefficients c[i] are stored. Usually, the record is not directly accessed. Instead, a polynomial is generated with the functions provided in the record such as Polynomial.base(..), Polynomial.fitting(..). Several functions are provided that operate on polynomials.

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
c[:] | Polynomial coefficients (c[1]*x^n + ... c[n]*x + c[n+1])

## Modelica_LinearSystems2.Math.isEqual

Determine whether two Real numbers are numerically identical (up to machine precision)

### Information

#### Syntax

>     result = isEqual(r1, r2);
>     result = isEqual(r1, r2, eps=0.0);

#### Description

The function call "`isEqual(r1, r2)`" returns true, if the two Real numbers r1 and r2 are the same up to a given precision eps. (result = abs(r1-r2) ≤ eps). Otherwise the function returns false. With the optional third argument eps the range can be defined, in which two Real numbers are treated as identical. The default is "eps = 0". Another useful value is, e.g., "eps = 10*Modelica.Constants.eps".

#### Example

>       Real r1 = 3;
>       Real r2 = 3;
>       Real r3 = 3.0001;
>       Boolean result;
>     algorithm
>       result := isEqual(r1,r2);          // = true
>       result := isEqual(r1,r3);          // = false
>       result := isEqual(r1,r3, eps=0.1); // = true

#### See also

Vectors.isEqual, Matrices.isEqual, Strings.isEqual

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

### Inputs

Name | Description
--- | ---
u1 | First scalar
u2 | Second scalar
eps | The two scalars are identical if abs(u1-u2) <= eps

### Outputs

Name | Description
--- | ---
result | = true, if abs(u1-u2) <= eps