This library provides functions operating on vectors of Complex numbers.
Extends from Modelica.Icons.Package (Icon for standard packages).Name | Description |
---|---|
![]() | Returns the p-norm of a complex vector |
![]() | Return length of a complex vector |
![]() | Return normalized complex vector such that length = 1 and prevent zero-division for zero vector |
![]() | Reverse vector elements (e.g., v[1] becomes last element) |
![]() | Sort elements of complex vector |
Vectors.norm(v); Vectors.norm(v,p=2); // 1 ≤ p ≤ ∞
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:
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)
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
Name | Description |
---|---|
v[:] | Vector |
p | Type of p-norm (often used: 1, 2, or Modelica.Constants.inf) |
Name | Description |
---|---|
result | p-norm of vector v |
Vectors.length(v);
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(..).
v = {2, -4, -2, -1}; length(v); // = 5
Name | Description |
---|---|
v[:] | Vector |
Name | Description |
---|---|
result | Length of vector v |
Vectors.normalize(v); Vectors.normalize(v,eps=100*Modelica.Constants.eps);
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.
normalize({1,2,3}); // = {0.267, 0.534, 0.802} normalize({0,0,0}); // = {0,0,0}
Name | Description |
---|---|
v[:] | Vector |
eps | if |v| < eps then result = v |
Name | Description |
---|---|
result[size(v, 1)] | Input vector v normalized to length=1 |
Vectors.reverse(v);
Vectors.reverse(v)
" returns the complex vector elements in reverse order.
Extends from Modelica.Icons.Function (Icon for functions).reverse({1,2,3,4}); // = {4,3,2,1}
Name | Description |
---|---|
v[:] | Vector |
Name | Description |
---|---|
result[size(v, 1)] | Elements of vector v in reversed order |
sorted_v = Vectors.sort(v); (sorted_v, indices) = Vectors.sort(v, ascending=true);
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].
Extends from Modelica.Icons.Function (Icon for functions).(v2, i2) := Vectors.sort({-1, 8, 3, 6, 2}); -> v2 = {-1, 2, 3, 6, 8} i2 = {1, 5, 3, 4, 2}
Name | Description |
---|---|
v[:] | Vector to be sorted |
ascending | = true if ascending order, otherwise descending order |
sortFrequency | = true, if sorting is first for imaginary then for real value; = false, if sorting is for absolute value |
Name | Description |
---|---|
sorted_v[size(v, 1)] | Sorted vector |
indices[size(v, 1)] | sorted_v = v[indices] |