Purpose |
To simplify Matrix Algebra calculations. |
Syntax |
MAT a1() = CON 'Set all elements of a1() to one MAT a1() = CON(expr) 'Set all elements of a1() to value of expr MAT a1() = IDN 'Establish a1() as an identity matrix MAT a1() = ZER 'Set all elements of a1() to zero MAT a1() = a2() + a3() 'Addition MAT a1() = a2() 'Assignment MAT a1() = INV(a2()) 'Inversion MAT a1() = (expr) * a2() 'Scalar Multiplication MAT a1() = a2() - a3() 'Subtraction MAT a1() = a2() * a3() 'Multiplication MAT a1() = TRN(a2()) 'Transposition |
Remarks |
Array names with the MAT statements may optionally include a set of empty parentheses. The following are both equally valid, but the inclusion of the parentheses improves clarity of the code: MAT a1 = CON MAT a1() = CON MAT CON, IDN ZER + - = and TRN operations are valid with Byte, Word, Double-word, Integer, Long-integer, Quad-integer, Single-precision, Double-precision and Extended-precision arrays. Matrix * and INV operations are only valid with floating-point numbers: Single-precision, Double-precision and Extended-precision arrays. It is the programmer's responsibility to ensure that arrays used with MAT are of the appropriate size and type. All operations involving two or more arrays require that they be of exactly the same size and type, without exception. Failure to adhere causes undefined results. In the interest of execution speed, no error checking is performed at run-time. Every scalar value denoted here as 'expr' must be enclosed in parentheses. Although Matrix operations tend to imply a two-dimensional array, unless otherwise noted (such as with MAT IDN, *, TRN), MAT may be used with arrays of one to eight dimensions. It is permissible to specify one array for multiple MAT parameters. |
Example |
MAT array1() = IDN This establishes array1 as an identity matrix,
with all diagonal elements as 1 and all others as zero. This produces
undefined results if array1 is not a "square" matrix. Each element of array2 is multiplied by the scalar value of the expr, then assigned to array1. MAT array1() = TRN(array2()) Transposes the row and columns from array2 to array1. Arrays must be equivalent: array1(5,2) and array2(2,5). Only a square matrix may be transposed to itself. MAT array1() = INV(array2()) Inverts the array from array2 to array1. Only a square matrix may be inverted. Proof: If array1 is then multiplied by array2, the resulting "array3" will be equal to an Identify Matrix, (MAT array3 = array1 * array2 ' array3 should now be equal to "MAT array3 IDN"). MAT a() = b() * c() Array multiplication occurs as follows: ' Row Column assumption: ' array [a]l,n = [b]l,m * [c]m,n
FOR i = 1 TO l ' Row [a]l = Row [b]l FOR j = 1 TO n ' Column [a]n = Column [c]n a(i,j) = 0# ' # if Double-precision FOR k = 1 TO m ' Column [b]m = Row [c]m a(i,j) = a(i,j) + b(l,k) * c(k,j) NEXT NEXT NEXT |