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

Constructor Index

 o Matrix(int, int)
This allocates a matrix of specified dimensions.
 o 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.
 o Matrix(Matrix)
This creates a duplicate of the Matrix supplied to it.

Method Index

 o add(Matrix, Matrix)
Adds two matrices together.
 o col(int)
extracts the ith column from the matrix.
 o cols()
returns the number of colums in the matrix
 o gauss_elim()
Performs Gaussian elimination upon a copy of the matrix.
 o getEntry(int, int)
Returns the entry at the specified row and column.
 o main(String[])
This is test code used during implementation.
 o mul(Matrix)
instance version of multiplication.
 o mul(Matrix, Matrix)
Multiplies two matrices together.
 o row(int)
extracts the ith row from the matrix.
 o rows()
returns the number of rows in the matrix
 o setEntry(int, int, double)
Sets the entry at the specified row and column to the specified value.
 o toString()
This converts the matrix to a string.
 o transpose()
returns the transpose of this matrix

Constructors

 o 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.
 o 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.
 o 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.

Methods

 o 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
 o 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.
 o 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.
 o 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.
 o 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.
 o mul
 public Matrix mul(Matrix r)
instance version of multiplication. calls static version to do the work.

 o transpose
 public Matrix transpose()
returns the transpose of this matrix

 o gauss_elim
 public Matrix gauss_elim()
Performs Gaussian elimination upon a copy of the matrix. Uses the private INTERNAL_gauss_elim() method.

 o getEntry
 public double getEntry(int r,
                        int c)
Returns the entry at the specified row and column.

 o 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.

 o rows
 public int rows()
returns the number of rows in the matrix

 o cols
 public int cols()
returns the number of colums in the matrix

 o main
 public static void main(String argv[])
This is test code used during implementation.


All Packages  Class Hierarchy  This Package  Previous  Next  Index