These are operations on matrices. The include the "simple" arithmetic operations (\+, \-, \*), as well as other standard matrix operations, such as inverse, transpose, augment, and gauss-jordan elimations.
\+ | [Method] |
Adds two matrices.
Synopsis
\+ (matrix1, matrix2) => (summation-matrix)
Parameters
matrix1 An instance of <matrix>
.matrix2 An instance of <matrix>
.
Return Values
summation-matrix An instance of <matrix>
.
Description
Adds two matrices. This is a binary operator that performs matrix addition on the matrices "matrix1" and "matrix2", storing the result in a new matrix "temp-mat", "temp-mat" is then returned on exit. Matrix addition is very simple, all it is is adding terms in corresponding positions
\- | [Method] |
Subtracts two matrices.
Synopsis
\- (matrix1, matrix2) => (difference-matrix)
Parameters
matrix1 An instance of <matrix>
.matrix2 An instance of <matrix>
.
Return Values
difference-matrix An instance of <matrix>
.
Description
Matrix subtraction is (surprise) just like matrix addition, where the element i,j in (A - B) is (A[i,j] - B[i,j])
\* | [Method] |
Multiplies a matrix by a scalar.
Synopsis
\* (a, matrix1) => (product-matrix)
Parameters
a An instance of <number>
.matrix1 An instance of <matrix>
.
Return Values
product-matrix An instance of <matrix>
.
Description
Multiplication of a matrix and a scalar quantity. This simply multiplies each element of the matrix by the scalar quantity.
\* | [Method] |
Multiplies a matrix by a scalar.
Synopsis
\* (a, matrix1) => (product-matrix)
Parameters
a An instance of <number>
.matrix1 An instance of <matrix>
.
Return Values
product-matrix An instance of <matrix>
.
Description
Same as the above
\*
, with the opposite order of the parameters.
\* | [Method] |
Multiplies two matrices.
Synopsis
\* (matrix1, matrix2) => (mult-matrix)
Parameters
matrix1 An instance of <number>
.matrix2 An instance of <matrix>
.
Return Values
mult-matrix An instance of <matrix>
.
Description
Multiplies two matrices. There are certain restrictions on what matrices can be multiplied. To multiply two matrices, the dimensions must be MxN for the first matrix, and NxP for the second. The result of the multiplication will be an MxP matrix. (Note, this implies A * B is not necessarily equal to B * A) The element i,j in A * B is the dot (inner) product of the ith row of A with the jth column of B. The dot product of a vector is the sum of the products of corresponding elements. That is, if vector V=[a,b,c,d] and vector W=[w,x,y,z] then V*W= aw + bx + cy + dz (Note that this is a scalar quantity).
The actual algorithm used was reproduced from Sedgewick's Algorithms, Ch. 36. Basically, the algorithm goes through the temporary matrix, filling out each element in the following way: For the i,jth element of the matrix, calculate the dot product an element at a time, by having a number k range from 0 to the dimension N of the matrix. Take A[i,k] and multiply it by B[k,j] to get one of the terms in the dot product. Continue this for each element in the MxP matrix to get the result.
augment-matrix | [Method] |
A special way to concatenate two matrices.
Synopsis
augment-matrix (matrix1, matrix2) => (augmented-matrix)
Parameters
matrix1 An instance of <number>
.matrix2 An instance of <matrix>
.
Return Values
augmented-matrix An instance of <matrix>
.
Description
The augment-matrix procedure will take matrices A and B and return a matrix | A B |.
gauss-jordan | [Method] |
Does a Gauss-Jordan elimination on a matrix.
Synopsis
gauss-jordan (matrix1) => (solution-matrix)
Parameters
matrix1 An instance of <number>
.
Return Values
solution-matrix An instance of <matrix>
.
Description
This procedure does gauss-jordan elimation on a matrix of dimension N by N + 1. The first N columns are the coefficents in a set of simultaneous equations, and the last column is a solution vector. The matrix that is returned is an N by 1 matrix contaning the solution for each variable. For example, if you have a system of equations like this:
2x + 4y - 2z = 2 4x + 9y - 3z = 8 -2x - 3y + 7z = 10The matrix representing this would be
| 2 4 -2 2 | | 4 9 -3 8 | | -2 -3 7 10 |The solution matrix returned would be:
| -1 | | 2 | | 2 |where x is -1, y is 2, and z is 2
inverse | [Method] |
Finds the inverse of a matrix.
Synopsis
inverse (matrix1) => (inverted-matrix)
Parameters
matrix1 An instance of <number>
.
Return Values
inverted-matrix An instance of <matrix>
.
Description
Finds the inverse of a matrix, by using a modified gauss-jordan elimination. Given any matrix, if there is an inverse, the inverse will be returned, otherwise, an error will be signalled. To determine the existance of an inverse, the algorithm finds the upper triangular matrix, and then multiplies all of the elements along the main diagonal. If the result of this multiplication is zero, there is no inverse, otherwise, there is gaurenteed to be an inverse.
det | [Method] |
Returns the determinant of a matrix.
Synopsis
det (matrix1) => (determinant)
Parameters
matrix1 An instance of <number>
.
Return Values
determinant An instance of <number>
.
Description
This just does what the first half of inverse does. It reduces the matrix to the upper triangular form, and then returns the product of all of the elements along the diagonal. This is the determinant of the matrix.
inverse | [Method] |
Returns the matrix transposed.
Synopsis
inverse (matrix1) => (transposed-matrix)
Parameters
matrix1 An instance of <number>
.
Return Values
transposed-matrix An instance of <matrix>
.
Description
This function transposes a matrix. It takes a M by N matrix and turns it into an N by M matrix. All it does is take the i,jth element in the M by N matrix, and turns it into the j,ith element in the N by M matrix.