# Using Arrays of Arbitrary Dimension

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 Ai,j. The equation,

```L = Ai,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,

```Bi,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.

Representing a 4 by 6 by 2 Dimensional Array as Elements [24*K + 4*J + I] of a One-Dimensional Array. For example: Element [2,4,1] is [24*1 + 4*4 + 2] = [42].