1.05 Types, Arrays and Matrices

Types

To be added.

See 5.01 Types.

Arrays

Within LynPlex an array only has a single dimension, but this does not prevent you having multi-dimension arrays. Within an array each element can be any data type including an array. It is therefore possible to define an element of an array as another array. This process can be repeated as many times as required to create multi-dimensional arrays.

Arrays can be created as the output of various commands and functions. They can also be created by direct assignment.

The following statement creates a simple array of four elements.

a = {1, 2, 3, 4}

Nested arrays are allowed and can be assigned to array elements.

a = {{1,2} , {3,4}}
b = {1, 2, 3}
c = {4, 5}
b(2) = c
put b            // displays {1,2,{4,5},3}

You can access elements by using subscripts in parentheses.

b(2, 1) = 16
put b(2, 1)      // displays 16
put b(2)         // displays {4,16}

See 5.02 Arrays.

Compound Variables

Although there are small differences, compound variables can be considered to be the same as arrays. The above example could be entered as:

b.2.1 = 16
put b.2.1        // displays 16
put b.2          // displays {4,16}

Matrices

A matrix is essentially an array with defined dimensions.

The DIM command can be used to create arrays to be used as matrices and to provide a range of values for the subscripts. Initially the created array will be empty.

dim m(1 to 3, -1 to 1)
put " m =" m     // displays m = {{,,},{,,},{,,}}

LynPlex has commands for performing actions on matrices.

See 5.03 Matrix Operations.


lynplex/lp0105.txt · Last modified: 2015/01/06 13:46 (external edit)