phelps.math

Class Matrix

public class Matrix extends Object

Matrix manipulations: add, multiply, invert, transpose, determinant, Gauss-Jordan, simplex.

Version: $Revision: 1.6 $ $Date: 2003/02/06 06:56:10 $

See Also: "Introductory Linear Algebra with Applications, by John W. Brown and Donald R. Sherbert"

Constructor Summary
Matrix(int rows, int cols)
Create a new matrix of the indicated number of m rows and columns.
Matrix(double[][] x)
Matrix(Matrix m)
Create a new Matrix by copying (not sharing) the content of the one passed in.
Method Summary
Matrixadd(Matrix x)
Return new matrix that is sum of this and passed matrix.
doubledeterminant()
Return the determinant of the matrix.
booleanequals(Object o)
doubleget(int row, int col)
intgetCols()
intgetRows()
inthashCode()
Matrixinvert()
Returns new matrix that is the inverse.
double[]maximize(double[] maximize)
Treat matrix as a system of equations and maximize the passed program with the Simplex method.
Matrixmultiply(double s)
Return new matrix that is result of multiplying each element by the scalar s.
Matrixmultiply(Matrix x)
Return new matrix that is product of this and passed matrix.
voidset(int row, int col, double val)
double[]solveGaussJordan(int vars)
Treat the m x n matrix as a system of m equations in m unknowns, with the first m of n columns as coefficients, and the remaining n-m columns (typically n-m == 1) as constants.
Matrixtranspose()
Return a new matrix that is the transpose of this one.

Constructor Detail

Matrix

public Matrix(int rows, int cols)
Create a new matrix of the indicated number of m rows and columns.

Matrix

public Matrix(double[][] x)

Matrix

public Matrix(Matrix m)
Create a new Matrix by copying (not sharing) the content of the one passed in.

Method Detail

add

public Matrix add(Matrix x)
Return new matrix that is sum of this and passed matrix. Matrices must have same dimensions.

Throws: IllegalArgumentException if passed matrix is of different dimension.

determinant

public double determinant()
Return the determinant of the matrix.

equals

public boolean equals(Object o)

get

public double get(int row, int col)

getCols

public int getCols()

Returns: number of columns in matrix

getRows

public int getRows()

Returns: number of rows in matrix

hashCode

public int hashCode()

invert

public Matrix invert()
Returns new matrix that is the inverse. Subsequently multiplying this matrix by its inverse yields an identity matrix.

Throws: IllegalStateException if matrix is not invertable.

maximize

public double[] maximize(double[] maximize)
Treat matrix as a system of equations and maximize the passed program with the Simplex method. Returns vector that is the solution (which is the same as the first row of the mutated matrix). If maximum is unbounded, null is return.

Returns: values for the variables in [0..vars-1] and maximum obtained at these settings in [vars].

multiply

public Matrix multiply(double s)
Return new matrix that is result of multiplying each element by the scalar s.

multiply

public Matrix multiply(Matrix x)
Return new matrix that is product of this and passed matrix.

Throws: IllegalArgumentException if passed matrix is of different dimension.

set

public void set(int row, int col, double val)

solveGaussJordan

public double[] solveGaussJordan(int vars)
Treat the m x n matrix as a system of m equations in m unknowns, with the first m of n columns as coefficients, and the remaining n-m columns (typically n-m == 1) as constants. The resulting mutated matrix reports the solution such that the first variable equals the value get(0, m+1), the second at get(1, m+1), and so on. If there were multiple equations with the same coeffients but different constants, their results are available at get(0, m+2), get(1, m+2), and so on. The first (and typically only) solution vector is also the method's return value. If underdetermined....

transpose

public Matrix transpose()
Return a new matrix that is the transpose of this one.