MAT statements ☆☆

Full BASIC provides MAT statements, which perform matrix operations.

Let A, B and C be arrays, m, n and p be numeric expressions below.

MAT A = B
substitutes B for A, where A and B have the same dimension.

MAT A = ZER
substitutes 0 for all elements of A.

MAT A = ZER(m) when A is 1-dimensional
MAT A = ZER(m, n) when A is 2-dimensional
MAT A = ZER(m, n, p) when A is 3-dimensional
changes the upper bounds of A and substitutes 0 for all elements.
Note that the dimension of an array do not change.

MAT A = CON
substitutes 1 for all elements of A.

MAT A = CON(m)
MAT A = CON(m, n)
MAT A = CON(m, n, p)
changes the upper bounds of A and substitutes 1 for all elements.

MAT A=B+C
MAT A=B-C
MAT A=B*C
Substitutes the sum, difference or product of B and C for A.
In case of the product, dimensions of A, B and C must be one of 1-2-1, 1-1-2, 2-2-2.

MAT A=(numeric_expression)*B
Scalar multiplication.
If numeric_expression is a constant, a function reference or a variable, parentheses can be omitted.
Example. Let x be a numeric variable.
MAT A=x*A
MAT A=(2*x)*B
MAT A=ABS(x+3)*B


MAT A=(numeric_expression)*CON
The value of numeric_expression is assigned to all elements of A.

Let A and B be 2-dimensional arrays.

MAT A = IDN
substitutes the identity matrix for A.
If A is not square, an exception of 6004 shall be raised.

MAT A = IDN(n)
substitutes n×n identity matrix for A.

MAT A=INV(B)
substitutes the inverse matrix of B for A.

MAT A=TRN(B)
substitutes the transposed matrix of B for A.

Cross Product (Original Enhancement)
Let A, B and C be 1-dimensional arrays.
MAT A=CROSS(B,C)
Substitutes the outer product of B and C for A.
If the size of B and C are not 3, an exception of extype 6001 shall be raised.

Notes.

Although a MAT statement may change the size of an array, the lower bounds of an array does not change, and only the upper bounds are adjusted for the new size.
For example, when an array such as A(1)=1,A(2)=2,A(3)=3 is substituted for an array B with the lower bound 0, B becomes as B(0)=1,B(1)=2,B(2)=3.
That is, MAT B=A means
LET B(0)=A(1)
LET B(1)=A(2)
LET B(2)=A(3)

Note.
MAT A=ZER(m TO n) does not make the lower bound of A into m.
This statement keeps the lower bound of A and changes only the size of A to n-m+1.
If you want to change the lower bound of an array, use a MAT READ statement or an original enhancement MAT REDIM.

Note.
If a MAT statement yields that the number of elements of an array exceeds the number of elements first declared, an exception of extye 5001 shall be raised.

Note.
Addition, subtraction, or multiplication of only two matrices can be performed.
Although MAT A=B*C*D can be compiled when A, B, C and D are all 2-dimensional, this MAT statement is a transform-assignment and an exception shall be raised unless the size of every matrix is 4× 4. Moreover, even if the size of every matrix is 4×4, the precision of result shall be that of the graphics subsystem (currently binary double precision).