All Packages Class Hierarchy This Package Previous Next Index
Class benno.linalg.Matrix
java.lang.Object
|
+----benno.linalg.Matrix
- public class Matrix
- extends Object
- implements Serializable
This class defines a real rectangular matrix.
All public methods except setEntry are non-mutating - that is,
they do not change the matrices passed to them; instead they allocate
new matrices. This can slow calculations down and be less memory
efficient, but it makes it easy to write programs that use this class.
- Version:
- $Revision: 1.4 $
- Author:
- Ben Clifford
-
Matrix(int, int)
- This allocates a matrix of specified dimensions.
-
Matrix(int, int, Matrix)
- This allocates a matrix of specified dimensions, and then
initialises it with entries from the supplied matrix, which may
have different dimensions.
-
Matrix(Matrix)
- This creates a duplicate of the Matrix supplied to it.
-
add(Matrix, Matrix)
- Adds two matrices together.
-
col(int)
- extracts the ith column from the matrix.
-
cols()
- returns the number of colums in the matrix
-
gauss_elim()
- Performs Gaussian elimination upon a copy of the matrix.
-
getEntry(int, int)
- Returns the entry at the specified row and column.
-
main(String[])
- This is test code used during implementation.
-
mul(Matrix)
- instance version of multiplication.
-
mul(Matrix, Matrix)
- Multiplies two matrices together.
-
row(int)
- extracts the ith row from the matrix.
-
rows()
- returns the number of rows in the matrix
-
setEntry(int, int, double)
- Sets the entry at the specified row and column to the specified value.
-
toString()
- This converts the matrix to a string.
-
transpose()
- returns the transpose of this matrix
Matrix
public Matrix(int rs,
int cs)
- This allocates a matrix of specified dimensions.
- Parameters:
- rs - the number of rows that this matrix will have.
- cs - the number of columns that this matrix will have.
Matrix
public Matrix(int rs,
int cs,
Matrix m)
- This allocates a matrix of specified dimensions, and then
initialises it with entries from the supplied matrix, which may
have different dimensions. Possibly, not all elements will be used,
and possibly there will not be sufficient, in which case, entries
will be left with their default value.
- Parameters:
- rs - the number of rows that this matrix will have.
- cs - the number of columns that this matrix will have.
- m - the matrix from which initial values will be taken.
Matrix
public Matrix(Matrix m)
- This creates a duplicate of the Matrix supplied to it.
I am not sure if this is the best way to duplicate an object,
but it suffices. It is similar to Matrix(rs,cs,m) except
the values for rs and cs are taken from m.
- Parameters:
- m - the matrix to be duplicated.
toString
public String toString()
- This converts the matrix to a string.
- Returns:
- s a string of the format:
Matrix(rows,cols){
[ n n n ]
[ n n n ]
}
- Overrides:
- toString in class Object
add
public static Matrix add(Matrix a,
Matrix b)
- Adds two matrices together. The two supplied matrices must have
the same dimension.
- Parameters:
- a - one of the matrices to add.
- b - the other of the matrices to add.
- Returns:
- s a new matrix containing the sum a+b
- Throws: MatrixException
- This exception is thrown when the two matrices a,b do not have
exactly the same dimensions.
row
public Matrix row(int i)
- extracts the ith row from the matrix.
- Parameters:
- i - The row to extract (ranging from 0 .. rows-1)
- Returns:
- a new matrix of dimension 1x(cols), containing the
contents of the ith row of the matrix.
- Throws: MatrixException
- This exception is thrown when the parameter i is out of range.
col
public Matrix col(int i)
- extracts the ith column from the matrix.
- Parameters:
- i - The column to extract (ranging from 0 .. cols-1)
- Returns:
- a new matrix of dimension (rows)x1, containing the
contents of the ith column of the matrix.
- Throws: MatrixException
- This exception is thrown when the parameter i is out of range.
mul
public static Matrix mul(Matrix l,
Matrix r)
- Multiplies two matrices together. It does so in a recursive
fashion - inefficient but quick to implement. Maybe update later.
- Parameters:
- l - The matrix on the left hand side of the multiplication, of
dimension m x p, where p is the same as for parameter r.
- r - The matrix on the right hand side of the multiplication,
of dimension p x n, where p is the same as for parameter l.
- Returns:
- s A new matrix of dimension m x n, containing the result
of the matrix multiplication lr.
- Throws: MatrixException
- This is thrown when the dimensions of the parameter matrices are
inconsistent - i.e. m*p q*n matrices with p!=q.
mul
public Matrix mul(Matrix r)
- instance version of multiplication. calls static version to do the
work.
transpose
public Matrix transpose()
- returns the transpose of this matrix
gauss_elim
public Matrix gauss_elim()
- Performs Gaussian elimination upon a copy of the matrix.
Uses the private INTERNAL_gauss_elim() method.
getEntry
public double getEntry(int r,
int c)
- Returns the entry at the specified row and column.
setEntry
public void setEntry(int r,
int c,
double v)
- Sets the entry at the specified row and column to the specified value.
WARNING! THIS IS A MUTATING METHOD - it causes the matrix to be
changed.
rows
public int rows()
- returns the number of rows in the matrix
cols
public int cols()
- returns the number of colums in the matrix
main
public static void main(String argv[])
- This is test code used during implementation.
All Packages Class Hierarchy This Package Previous Next Index