variables, not local variables. 89/92+ functions cannot write to global variables, only local variables, so
sorta will not work in a function.
None the less, this method is sufficiently short that it can be embedded into your programs. The
necessary global variable can be deleted when your program exits.
(Credit to Daniel Lloyd)
[3.15] Turn Pretty Print off to display commas in lists, matrices
If Pretty Print is turned On, list and vector elements are separated with spaces in the history display:
{1,2,3} is shown as {1 2 3}
When Pretty Print is turned off, the elements are separated with commas:
{1,2,3} is shown as {1,2,3}
(Credit to Glenn E. Fisher)
[3.16] Use arrays with more than two dimensions
The 89/92+ can manipulate 1-dimensional data structures (lists and vectors), and 2-dimensional data
structures (matrices and data variables). The number of dimensions is called the rank. Lists and
vectors have a rank of 1. Matrices and data variables have a rank of 2. Matrices with rank greater than
two are useful in many cases. For example, arrays of rank 3 can represent fields and other physical
models. Arrays of rank 3 and 4 can be used to represent tensors.
This tip shows how to create and store arrays of any rank on the 89/92+, and how to store and recall
elements of those arrays. It also shows how many built-in list functions can be used to manipulate
high-rank arrays, and gives a program that finds the transpose of a rank-3 array.
I use the built-in list data structure to store the arrays, because a list can represent an array of any
desired rank. First, consider a 3-dimensional array with dimensions {d
1
, d
2
, d
3
}. An element's location in
this array is defined as {a
1
, a
2
, a
3
}, where
1 [ a
1
[ d
1
1 [ a
2
[ d
2
1 [ a
3
[ d
3
For example, a 2x3x4 matrix would have d = {2,3,4}, and an element in the matrix might be located at a
= {2,1,3}.
To create an array mat1 with all zero elements, use
newlist(d1*d2*d3)→mat1
For example, to create a 2 x 3 x 4 array, use
newlist(24)→mat1
The array elements are saved in the list such that the last index changes most rapidly as we move
towards the end of the list. If we have a 2x2x2 array, and we label the elements as e
a1,a2,a3
, then the list
would look like this:
3 - 10