# Using Arrays of Arbitrary Dimension

### From Support

Four-dimensional arrays will be sufficient to meet most simulation modeling needs. However, if you find it necessary to have higher dimensional arrays, the method discussed here is easily implemented.

Assume that one conceptually is working with a two-dimensional (N by M) array, A. That is, the element in the ith "row" and jth "column" of this array is the value of the variable A_{i,j}. The equation,

L = A_{i,j},

written in SIGMA is

L = A[N*J+I].

Recall that we start indexing arrays with zero, not with one.

This indexing scheme can be extended to more than just two dimensions. For example, element,

B_{i,j,k}

,of an N by M by L array would be the element,

B[N*M*K+N*J+I],

of a single dimensional array, B[.]. The logical structure for a three-dimensional array of size (4,6,2) is shown below. Each element of the single dimensional array, B[.], is shown in a cell.

A more sophisticated array indexing scheme uses "ragged" arrays, which sometimes saves memory. Here the total number of elements in all rows strictly less than I is the value of the variable M[I]. The i,jth element of the ragged array,

A,

is given by the nested arrays

A[M[I]+J].

When an element is added to the array, both the M and A arrays are updated (resulting in some additional computational overhead). Ragged arrays can be useful when the rows of a matrix are of unequal length (for example, the i,jth element is some characteristic of the ith customer in the jth queue). The trade-off in using a ragged array is favorable when the rows (or columns) of the array are of significantly differing lengths.