Purpose: A utility class that can be used to perform matrix arithmetic.
About the System: This class will be used by a 2D renderer and a 3D renderer (and, perhaps, other classes).
Details
Encapsulating Matrices:
double[][]
to hold the elements.
Dimensionality Problems:
null
or throw
an IllegalArgumentException
.
Side Effects:
The cofactor() Method:
/** * Calculate the cofactor of a square matrix * (i.e., the signed determinate of the mtraix with row * i and column j removed) * * @param a The matrix (mxm) * @param i The index of the row to exclude * @param j The index of the col to exclude * @return The cofactor */ public static double cofactor(double[][] a, int i, int j)
The det() Method:
/** * Calculate the determinant of a square matrix * * @param a The matrix (mxm) * @return The value of the determinant */ public static double det(double[][] a)
The identity() Method:
/** * Create an (nxn) identity matrix * * @param n The size of the (square) matrix * @return The identity matrix */ public double[][] identity(int n)
The minor() Method:
/** * Create a particular minor from a square matrix * * @param a The matrix (mxm) * @param i The index of the row to exclude * @param j The index of the col to exclude * @return The minor (i.e., a with row i and column j excluded) */ public static double minor(double[][] a, int i, int j)
The submatrix() Method:
/** * Remove a row and column from a matrix * * @param a The matrix (mxm) * @param i The index of the row to exclude * @param j The index of the col to exclude * @return The submatrix (i.e., a with row i and column j excluded) */ public static double[][] submatrix(double[][] a, int i, int j)
The sum() Method:
/** * Add two matrices * * @param a One matrix * @param b The other matrix * @return a + b */ public static double[][] sum(double[][] a, double[][] b)
The times(double[], double[][]) Method:
/** * Multiply a row vector and a matrix * * @param v The row vector (1xn) * @param m The matrix (nxm) * @return The resulting row vector (1xm) */ public static double[] times(double[] v, double[][] m)
The times(double[][], double[][]) Method:
/** * Multiply two matrices * * @param a The first matrix (mxn) * @param b The second matrix (nxs) * @return The resulting matrix (mxs) */ public static double[][] times(double[][] a, double[][] b)
The transpose() Method:
/** * Create the transpose of a matrix * * @param a The matrix * @return a tranposed */ public static double[][] transpose(double[][] a)
Copyright 2007