Within the Modelica_LinearSystems2 Library the operator record Complex is widely used. This record was introduced together with Modelica Standard Library 3.2 as a top-level record outside of the Modelica Library. Introducing this record, a complex number, e.g. c = 1 + 2*j, can be simply generated by the following declaration:
c = Complex(1, 2)
Since support of operation overloading has been enabled in the Modelica language, the record Complex also enables mathematical operations being applied on complex numbers. The principle is that if there is e.g. an operation "c1 + c2" for which the operation '+' is not defined, it will be determined whether "c1" is a record type and, if it is, whether it contains a function '+'. If applicable, this function call then replaces the above operation, i.e,. "c1 + c2" is interpreted as Complex.'+'(c1, c2). In other words, an operation like c3 = c1 + c2 can now be realized by
import Modelica.ComplexMath.j; // same as constant Complex j = Complex(0,1); Complex c1 = 1 + 3*j; // = Complex.'+'(Complex(1), Complex.'*'(Complex(3),j)); Complex c2 = Complex(1, -5); // equivalent to definition of c1 Complex c3 = c1 + c2; Complex c4 = c1 * c2;
and
Modelica.Utilities.Streams.print("c3 = " + String(c3)); Modelica.Utilities.Streams.print("c4 = " + String(c4));
results in
c3 = 2 - 2*j c4 = 16 - 2*j
For details see Modelica Language Specification version 3.4, Chapter 14.
Besides the basic arithmetic given in Complex record, further mathematical operations on complex numbers can be found in Modelica.ComplexMath. Some advanced functions, especially those concerning vectors and matrices of complex numbers, are collected in ComplexMathAdds.