This package contains basic mathematical functions operating on complex numbers (such as sin(..)), as well as functions operating on vectors of complex numbers.
Extends from Modelica.Icons.Package (Icon for standard packages).
| Name | Description |
|---|---|
| j=Complex(0, 1) | Imaginary unit |
| Library of functions operating on complex vectors | |
| Sine of complex number | |
| Cosine of complex number | |
| Tangent of complex number | |
| Arc-sine of complex number | |
| Arc-cosine of complex number | |
| Arc-tangent of complex number | |
| Hyperbolic-sine of complex number | |
| Hyperbolic-cosine of complex number | |
| Hyperbolic-tangent of complex number | |
| Area-hyperbolic-sine of complex number | |
| Area-hyperbolic-cosine of complex number | |
| Area-hyperbolic-tangent of complex number | |
| Exponential of complex number | |
| Logarithm of complex number | |
| Absolute value of complex number | |
| Phase angle of complex number | |
| Conjugate of complex number | |
| Real part of complex number | |
| Imaginary part of complex number | |
| Complex from polar representation | |
| Square root of complex number | |
| Return maximum element of complex vector | |
| Return minium element of complex vector | |
| Return sum of complex vector | |
| Return product of complex vector |
final constant Complex j = Complex(0,1) "Imaginary unit";
This function returns the Complex sine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | sin(c1) |
function sin "Sine of complex number" input Complex c1 "Complex number"; output Complex c2 "sin(c1)"; algorithm c2 := (exp(Complex(-c1.im, +c1.re)) - exp(Complex(+c1.im, -c1.re)))/Complex(0, 2);end sin;
This function returns the Complex cosine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = cos(c1) |
function cos "Cosine of complex number" input Complex c1 "Complex number"; output Complex c2 "= cos(c1)"; algorithm c2 := (exp(Complex(-c1.im, +c1.re)) + exp(Complex(+c1.im, -c1.re)))/2;end cos;
This function returns the Complex tangent of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = tan(c1) |
function tan "Tangent of complex number" input Complex c1 "Complex number"; output Complex c2 "= tan(c1)"; algorithm c2 := sin(c1)/cos(c1);end tan;
This function returns the inverse Complex sine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | arc_sin(c1) |
function asin "Arc-sine of complex number" input Complex c1 "Complex number"; output Complex c2 "arc_sin(c1)"; algorithm c2 := -j*log(j*c1 + 'sqrt'(1 - c1*c1));end asin;
This function returns the inverse Complex cosine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = arc_cos(c1) |
function acos "Arc-cosine of complex number" input Complex c1 "Complex number"; output Complex c2 "= arc_cos(c1)"; algorithm c2 := -j*log(c1 + j*'sqrt'(1 - c1*c1));end acos;
This function returns the inverse Complex tangent of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = arc_tan(c1) |
function atan "Arc-tangent of complex number" input Complex c1 "Complex number"; output Complex c2 "= arc_tan(c1)"; algorithm c2 := 0.5*j*log((j + c1)/(j - c1));end atan;
This function returns the Complex hyperbolic sine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | sinh(c1) |
function sinh "Hyperbolic-sine of complex number" input Complex c1 "Complex number"; output Complex c2 "sinh(c1)"; algorithm c2 := Complex(Math.sinh(c1.re)*Math.cos(c1.im), Math.cosh(c1.re)*Math.sin(c1.im));end sinh;
This function returns the Complex hyperbolic cosine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = cosh(c1) |
function cosh "Hyperbolic-cosine of complex number" input Complex c1 "Complex number"; output Complex c2 "= cosh(c1)"; algorithm c2 := Complex(Math.cosh(c1.re)*Math.cos(c1.im), Math.sinh(c1.re)*Math.sin(c1.im));end cosh;
This function returns the Complex hyperbolic tangent of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = tanh(c1) |
function tanh "Hyperbolic-tangent of complex number" input Complex c1 "Complex number"; output Complex c2 "= tanh(c1)"; algorithm c2 := sinh(c1)/cosh(c1);end tanh;
This function returns the inverse Complex hyperbolic sine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | ar_sinh(c1) |
function asinh "Area-hyperbolic-sine of complex number" input Complex c1 "Complex number"; output Complex c2 "ar_sinh(c1)"; algorithm c2 := log(c1 + 'sqrt'(c1*c1 + 1));end asinh;
This function returns the inverse Complex hyperbolic cosine of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = ar_cosh(c1) |
function acosh "Area-hyperbolic-cosine of complex number" input Complex c1 "Complex number"; output Complex c2 "= ar_cosh(c1)"; algorithm c2 := log(c1 + (c1 + 1)*'sqrt'((c1 - 1)/(c1 + 1)));end acosh;
This function returns the inverse Complex hyperbolic tangent of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = ar_tanh(c1) |
function atanh "Area-hyperbolic-tangent of complex number" input Complex c1 "Complex number"; output Complex c2 "= ar_tanh(c1)"; algorithm c2 := 0.5*log((1 + c1)/(1 - c1));end atanh;
This function returns the Complex natural exponential of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = exp(c1) |
function exp "Exponential of complex number" input Complex c1 "Complex number"; output Complex c2 "= exp(c1)"; algorithm c2 := Complex(Math.exp(c1.re)*Math.cos(c1.im), Math.exp(c1.re)*Math.sin(c1.im));end exp;
This function returns the Complex natural logarithm of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = log(c1) |
function log "Logarithm of complex number"
input Complex c1 "Complex number";
output Complex c2 "= log(c1)";
algorithm
c2 := Complex(Modelica.Math.log('abs'(c1)), arg(c1));
end log;
This function returns the Real absolute of the Complex input, i.e., it's length.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c | Complex number |
| Type | Name | Description |
|---|---|---|
| Real | result | = abs(c) |
function 'abs' "Absolute value of complex number" input Complex c "Complex number"; output Real result "= abs(c)"; algorithm result := (c.re^2 + c.im^2)^0.5; //changed from sqrtend 'abs';
This function returns the Real argument of the Complex input, i.e., it's angle.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c | Complex number | |
| Angle | phi0 | 0 | Phase angle phi shall be in the range: -pi < phi-phi0 < pi [rad] |
| Type | Name | Description |
|---|---|---|
| Angle | phi | = phase angle of c [rad] |
function arg "Phase angle of complex number"
input Complex c "Complex number";
input Modelica.SIunits.Angle phi0=0
"Phase angle phi shall be in the range: -pi < phi-phi0 < pi";
output Modelica.SIunits.Angle phi "= phase angle of c";
algorithm
phi := Modelica.Math.atan3(
c.im,
c.re,
phi0);
end arg;
This function returns the Complex conjugate of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = c1.re - j*c1.im |
function conj "Conjugate of complex number" input Complex c1 "Complex number"; output Complex c2 "= c1.re - j*c1.im"; algorithm c2 := Complex(c1.re, -c1.im);end conj;
This function returns the real part of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c | Complex number |
| Type | Name | Description |
|---|---|---|
| Real | r | = c.re |
function real "Real part of complex number" input Complex c "Complex number"; output Real r "= c.re "; algorithm r := c.re;end real;
This function returns the imaginary part of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c | Complex number |
| Type | Name | Description |
|---|---|---|
| Real | r | = c.im |
function imag "Imaginary part of complex number" input Complex c "Complex number"; output Real r "= c.im "; algorithm r := c.im;end imag;
This function constructs a Complex number from it's length (absolute) and angle (argument).
| Type | Name | Default | Description |
|---|---|---|---|
| Real | len | abs of complex | |
| Angle | phi | arg of complex [rad] |
| Type | Name | Description |
|---|---|---|
| Complex | c | = len*cos(phi) + j*len*sin(phi) |
function fromPolar "Complex from polar representation" input Real len "abs of complex"; input Modelica.SIunits.Angle phi "arg of complex"; output Complex c "= len*cos(phi) + j*len*sin(phi)"; algorithm c := Complex(len*Modelica.Math.cos(phi), len*Modelica.Math.sin(phi));end fromPolar;
This function returns the Complex square root of the Complex input.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | c1 | Complex number |
| Type | Name | Description |
|---|---|---|
| Complex | c2 | = sqrt(c1) |
function 'sqrt' "Square root of complex number"
input Complex c1 "Complex number";
output Complex c2 "= sqrt(c1)";
algorithm
c2 := Complex(sqrt('abs'(c1))*Math.cos(arg(c1)/2), sqrt('abs'(c1))*Math.sin(arg(c1)/2));
end 'sqrt';
This function returns the largest element of the Complex input vector, defined by the Complex absolute.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | v[:] | Vector |
| Type | Name | Description |
|---|---|---|
| Complex | result | Element of v with largest absolute value |
| Integer | index | v[index] has the largest absolute value |
function 'max' "Return maximum element of complex vector"
input Complex v[:] "Vector";
output Complex result "Element of v with largest absolute value";
output Integer index "v[index] has the largest absolute value";
protected
Real absv_i;
Real absres;
algorithm
if size(v,1) > 0 then
absres := 'abs'(v[1]);
index := 1;
for i in 2:size(v,1) loop
absv_i := 'abs'(v[i]);
if absv_i > absres then
absres := absv_i;
index := i;
end if;
end for;
result :=v[index];
else
result := Complex(0);
index := 0;
end if;
end 'max';
This function returns the smallest element of the Complex input vector, defined by the Complex absolute.
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | v[:] | Vector |
| Type | Name | Description |
|---|---|---|
| Complex | result | Element of v with smallest absolute value |
| Integer | index | v[index] has the smallest absolute value |
function 'min' "Return minium element of complex vector"
input Complex v[:] "Vector";
output Complex result "Element of v with smallest absolute value";
output Integer index "v[index] has the smallest absolute value";
protected
Real absv_i;
Real absres;
algorithm
if size(v,1) > 0 then
absres := 'abs'(v[1]);
index := 1;
for i in 2:size(v,1) loop
absv_i := 'abs'(v[i]);
if absv_i < absres then
absres := absv_i;
index := i;
end if;
end for;
result :=v[index];
else
result := Complex(0);
index := 0;
end if;
end 'min';
This function returns the Complex sum of the Complex input vector
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | v[:] | Vector |
| Type | Name | Description |
|---|---|---|
| Complex | result | Complex sum of vector elements |
function 'sum' "Return sum of complex vector"
input Complex v[:] "Vector";
output Complex result "Complex sum of vector elements";
algorithm
result:=Complex(0);
for i in 1:size(v,1) loop
result:=result + v[i];
end for;
end 'sum';
This function returns the Complex product of the Complex input vector
| Type | Name | Default | Description |
|---|---|---|---|
| Complex | v[:] | Vector |
| Type | Name | Description |
|---|---|---|
| Complex | result | Complex product of vector elements |
function 'product' "Return product of complex vector"
input Complex v[:] "Vector";
output Complex result "Complex product of vector elements";
algorithm
result:=Complex(1);
for i in 1:size(v,1) loop
result:=result * v[i];
end for;
end 'product';