REDUCE

14.2 Matrix Variables

An identifier may be declared a matrix variable by the declaration matrix. The size of the matrix may be declared explicitly in the matrix declaration, or by default in assigning such a variable to a matrix expression. For example,

        matrix x(2,1),y(3,4),z;

declares x to be a 2 x 1 (column) matrix, y to be a 3 x 4 matrix and z a matrix whose size is to be declared later.

Matrix declarations can appear anywhere in a program. Once a symbol is declared to name a matrix, it can not also be used to name an array, operator or a procedure, or used as an ordinary variable. It can however be redeclared to be a matrix, and its size may be changed at that time. Note however that matrices once declared are global in scope, and so can then be referenced anywhere in the program. In other words, a declaration within a block (or a procedure) does not limit the scope of the matrix to that block, nor does the matrix go away on exiting the block (use clear instead for this purpose). An element of a matrix is referred to in the expected manner; thus x(1,1) gives the first element of the matrix x defined above. References to elements of a matrix whose size has not yet been declared leads to an error. All elements of a matrix whose size is declared are initialized to 0. As a result, a matrix element has an instant evaluation property and cannot stand for itself. If this is required, then an operator should be used to name the matrix elements as in:

        matrix m; operator x;  m := mat((x(1,1),x(1,2));


Hosted by Download REDUCE Powered by MathJax