d is a 3-element list that specifies the list dimensions as {d
1
, d
2
, d
3
}
m is the array list or the name of the array list
m3rcl() returns a scalar result. To get the element at location {1,2,3} in a 2 x 3 x 4 array mat1, and save
it in the variable var1, use
m3rcl({1,2,3},{2,3,4},mat1)→var1
The index formula can be extended as needed for arrays of higher dimensions. For example, for a
4-dimensional array, the index formula is
[3]
k = a
4
+ a
3
− 1 d
4
+ a
2
− 1 d
3
d
4
+ a
1
− 1 d
2
d
3
d
4
This is expanded and factored to
[4]
k = d
4
d
3
d
2
a
1
− 1
+ a
2
− 1 + a
3
− 1 + a
4
This index formula is coded in routines m4sto() and m4rcl(), which are not shown here but are included
in the tip list code file tlcode.zip. The calling arguments are identical to m3sto() and m3rcl(), but note
that the the location and dimension lists have dimension 4, since the routines work on a 4-dimensional
array.
In general, for an n-dimensional array, you will sum n terms to find k. The terms are
(1st term) [5]
k = a
n
+
(2nd term)
a
n−1
− 1 d
n
+
(3rd term)
a
n−2
− 1 d
n
d
n−1
+
(4th term)
a
n−3
− 1 d
n
d
n−1
d
n−2
+
(5th term)
a
n−4
− 1 d
n
d
n−1
d
n−2
d
n−3
+...
To find the simplified form of the sum for arrays with rank greater than 4, use equation [4] as a pattern.
Begin by writing a nested product of the d terms, beginning with d
n
, and stop when you reach d
2
. I will
use a 5-dimension array as an example, and the simplified form looks like this, so far:
k = d
5
(d
4
(d
3
(d
2
(...
Next, start adding a
k
- 1 terms, and closing the parentheses as you go. Begin with a
1
:
k = d
5
(d
4
(d
3
(d
2
(a
1
− 1)+...
and continue until you reach a
n-1
:
k = d
5
(d
4
(d
3
(d
2
(a
1
− 1)+a
2
− 1)+a
3
− 1)+a
4
− 1)...
and finally add the a
n
term to the nested product:
k = d
5
(d
4
(d
3
(d
2
(a
1
− 1)+a
2
− 1)+a
3
− 1)+a
4
− 1)+a
5
This is the simplified form.
3 - 12