10 Matrix Operations

Reading and Printing Arrays

MAT READ

To assign values to an array from within a program, the DATA statement is used with MAT READ. Syntax for the MAT READ statement is as follows:

The MAT READ statement specifies entire arrays. Array elements are read in order with the right-most subscript varying fastest.

For example:

10   OPTION BASE 1
20   INTEGER A(2,2,2)
30   DATA 1,2,3,4,5,6,7,8
40   MAT READ A
50   MAT PRINT A
60   END

 1                   2

 3                   4

 5                   6

 7                   8
Values are read in the following order: A(1,1,1),A(1,1,2),A(1,2,1),A(1,2,2),A(2,1,1),A(2,1,2),A(2,2,1),A(2,2,2)

The following two statements are equivalent:

   MAT READ A                            READ A(*)
The MAT READ statement is programmable only; it cannot be executed from the keyboard.

MAT PRINT

The MAT PRINT statement allows the entire array to be output on the standard printer. Syntax for this statement is as follows:

The comma or semicolon following the array name specifies open or closed spacing between elements. A comma causes each element to be output left justified, in a 20-character field. A semicolon suppresses additional blanks. For example:

MAT PRINT A
 5              5              5              5
 5              5              5              5
 5              5              5              5
 5              5              5              5
MAT PRINT A,B
 5              5              5              5
 5              5              5              5
 5              5              5              5
 5              5              5              5
 2              2              2
 2              2              2
 2              2              2

MAT PRINT B;
 2  2  2
 2  2  2
 2  2  2
When an array has more than two dimensions, the last subscript varies fastest and defines the length of a row. For example:

10   OPTION BASE 1
20   INTEGER C(2,3,4)
30   FOR I=1 TO 2
40     FOR J=1 TO 3
50       FOR K=1 TO 4
60         C(I,J,K)=X
70         X=X+1
80       NEXT K
90     NEXT J
100  NEXT I
110  MAT PRINT C;
120  END

  0  1  2  3
  4  5  6  7
  8  9  10  11
  12  13  14  15
  16  17  18  19
  20  21  22  23
C(2,3,4) is treated as two matrices, each 3 by 4 for output or input.

File Input/Output

Entire arrays can be stored and retrieved by use of the MAT PRINT # and MAT READ # statements. Syntax for these statements are as follows:

MAT PRINT # file number [,record number]; array1 [,array2] [,END]

MAT READ # file number [,record number]; array1 [,array2] [,END]

Arrays are stored and retrieved, element-by-element, without regard to dimensionality. The last subscript varies fastest.

When the END parameter is specified in the MAT PRINT # statement, an end-of-file mark is printed at the end of the data; otherwise, an end-of-record mark is printed. For more details on PRINT #, READ #, and the other file storage operations, refer to page 195 .


Eloquence Language Manual - 19 DEC 2002