I have a vector of "barycenter" with size "5":
parameter Length barycenters[5] = {1, 2, 3, 4, 5};
and I would like to add the arguments of this vector inside another vector (b_prime) with size "7", meaning that intend to have b_prime = {0, 1, 2, 3, 4, 5, 10}. How is it possible to write a code line in Modelica to do so? I have tried the followings but I received errors:
parameter Length b_prime[7] = {0, barycenters[1:5], 10};
or
parameter Length b_prime[7] = {0, barycenters, 10};
I would appreciate your help.
The following code should do what you want:
model CombineVectors
import Modelica.SIunits.Length;
parameter Length barycenters[5] = {1, 2, 3, 4, 5};
parameter Length b_prime[7] = cat(1, {0}, barycenters, {10});
end CombineVectors;
Two important things to notice:
cat()
is the dimension in which the arrays shall be concatinatedcat()
except the first has the one dimension.From the Modelica Language Specification, Section 10.4.2 Array Concatenation:
The function cat(k,A,B,C,...)
concatenates arrays A,B,C,...
along dimension k
according to the following rules:
A, B, C, ...
must have the same number of dimensions, i.e., ndims(A) = ndims(B) = ...
A, B, C, ...
must be type compatible expressions (Section 6.6) giving the type of the elements of the result. The maximally expanded types should be equivalent. Real and Integer subtypes can be mixed resulting in a Real result array where the Integer numbers have been transformed to Real numbers.1 <= k <= ndims(A) = ndims(B) = ndims(C);
k
shall be an integer number.A, B, C, ...
must have identical array sizes with the exception of the size of dimension k
, i.e., size(A,j) = size(B,j)
, for 1 <= j <= ndims(A) and j <> k
.