'array()'

array()

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

The constructor function array(A,B,C,...) constructs an array from its arguments.

Examples

{1,2,3} is a 3-vector of type Integer
{{11,12,13}, {21,22,23}} is a 2x3 matrix of type Integer
{{{1.0, 2.0, 3.0}}} is a 1x1x3 array of type Real

Real[3] v = array(1, 2, 3.0);
type Angle = Real(unit="rad");
parameter Angle alpha = 2.0; // type of alpha is Real.
// array(alpha, 2, 3.0) or {alpha, 2, 3.0} is a 3-vector of type Real.
Angle[3] a = {1.0, alpha, 4}; // type of a is Real[3].

Description

The constructor function array(A,B,C,...) constructs an array from its arguments according to the following rules:
  • Size matching: All arguments must have the same sizes, i.e., size(A)=size(B)=size(C)=...
  • All arguments must be type compatible expressions giving the type of the elements. The data type of the result array is the maximally expanded type of the arguments. Real and Integer subtypes can be mixed resulting in a Real result array where the Integer numbers have been transformed to Real numbers.
  • Each application of this constructor function adds a one-sized dimension to the left in the result compared to the dimensions of the argument arrays, i.e., ndims(array(A,B,C)) = ndims(A) + 1 = ndims(B) + 1, ...
  • {A, B, C, ...} is a shorthand notation for array(A, B, C, ...).
  • There must be at least one argument [i.e., array() or {} are not defined].