Package Modelica.​ComplexMath.​Vectors
Library of functions operating on complex vectors

Information

This library provides functions operating on vectors of Complex numbers.

Extends from Modelica.​Icons.​FunctionsPackage (Icon for packages containing functions).

Package Contents

NameDescription
lengthReturn length of a complex vector
normReturns the p-norm of a complex vector
normalizeReturn normalized complex vector such that length = 1 and prevent zero-division for zero vector
reverseReverse vector elements (e.g., v[1] becomes last element)
sortSort elements of complex vector

Function Modelica.​ComplexMath.​Vectors.​norm
Returns the p-norm of a complex vector

Information

Syntax

Vectors.norm(v);
Vectors.norm(v,p=2);   // 1 ≤ p ≤ ∞

Description

The function call "Vectors.norm(v)" returns the Euclidean norm "sqrt(v*v)" of vector v. With the optional second argument "p", any other p-norm can be computed:

function Vectors.norm

Besides the Euclidean norm (p=2), also the 1-norm and the infinity-norm are sometimes used:

1-norm = sum(abs(v)) norm(v,1)
2-norm = sqrt(v*v) norm(v) or norm(v,2)
infinity-norm = max(abs(v)) norm(v,Modelica.Constants.inf)

Note, for any vector norm the following inequality holds:

norm(v1+v2,p) ≤ norm(v1,p) + norm(v2,p)

Example

  v = {2, -4, -2, -1};
  norm(v,1);    // = 9
  norm(v,2);    // = 5
  norm(v);      // = 5
  norm(v,10.5); // = 4.00052597412635
  norm(v,Modelica.Constants.inf);  // = 4

See also

Matrices.norm

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

Inputs

TypeNameDescription
Complexv[:]Vector
RealpType of p-norm (often used: 1, 2, or Modelica.Constants.inf)

Outputs

TypeNameDescription
Realresultp-norm of vector v

Function Modelica.​ComplexMath.​Vectors.​length
Return length of a complex vector

Information

Syntax

Vectors.length(v);

Description

The function call "Vectors.length(v)" returns the Euclidean length "sqrt(v*v)" of vector v. The function call is equivalent to Vectors.norm(v). The advantage of length(v) over norm(v)"is that function length(..) is implemented in one statement and therefore the function is usually automatically inlined. Further symbolic processing is therefore possible, which is not the case with function norm(..).

Example

  v = {2, -4, -2, -1};
  length(v);  // = 5

See also

Vectors.norm

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

Inputs

TypeNameDescription
Complexv[:]Vector

Outputs

TypeNameDescription
RealresultLength of vector v

Function Modelica.​ComplexMath.​Vectors.​normalize
Return normalized complex vector such that length = 1 and prevent zero-division for zero vector

Information

Syntax

Vectors.normalize(v);
Vectors.normalize(v,eps=100*Modelica.Constants.eps);

Description

The function call "Vectors.normalize(v)" returns the unit vector "v/length(v)" of vector v. If length(v) is close to zero (more precisely, if length(v) < eps), v is returned in order to avoid a division by zero. For many applications this is useful, because often the unit vector e = v/length(v) is used to compute a vector x*e, where the scalar x is in the order of length(v), i.e., x*e is small, when length(v) is small and then it is fine to replace e by v to avoid a division by zero.

Since the function is implemented in one statement, it is usually inlined and therefore symbolic processing is possible.

Example

  normalize({1,2,3});  // = {0.267, 0.534, 0.802}
  normalize({0,0,0});  // = {0,0,0}

See also

Vectors.length

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

Inputs

TypeNameDescription
Complexv[:]Vector
Realepsif |v| < eps then result = v

Outputs

TypeNameDescription
Complexresult[size(v, 1)]Input vector v normalized to length=1

Function Modelica.​ComplexMath.​Vectors.​reverse
Reverse vector elements (e.g., v[1] becomes last element)

Information

Syntax

Vectors.reverse(v);

Description

The function call "Vectors.reverse(v)" returns the complex vector elements in reverse order.

Example

  reverse({1,2,3,4});  // = {4,3,2,1}

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

Inputs

TypeNameDescription
Complexv[:]Vector

Outputs

TypeNameDescription
Complexresult[size(v, 1)]Elements of vector v in reversed order

Function Modelica.​ComplexMath.​Vectors.​sort
Sort elements of complex vector

Information

Syntax

           sorted_v = Vectors.sort(v);
(sorted_v, indices) = Vectors.sort(v, ascending=true);

Description

Function sort(..) sorts a Real vector v in ascending order and returns the result in sorted_v. If the optional argument "ascending" is false, the vector is sorted in descending order. In the optional second output argument the indices of the sorted vector with respect to the original vector are given, such that sorted_v = v[indices].

Example

  (v2, i2) := Vectors.sort({-1, 8, 3, 6, 2});
       -> v2 = {-1, 2, 3, 6, 8}
          i2 = {1, 5, 3, 4, 2}

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

Inputs

TypeNameDescription
Complexv[:]Vector to be sorted
Booleanascending= true if ascending order, otherwise descending order
BooleansortFrequency= true, if sorting is first for imaginary then for real value; = false, if sorting is for absolute value

Outputs

TypeNameDescription
Complexsorted_v[size(v, 1)]Sorted vector
Integerindices[size(v, 1)]sorted_v = v[indices]

Generated 2018-12-12 12:14:36 EST by MapleSim.