Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Multivalent API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## phelps.math
Class Matrix

    java.lang.Object
      phelps.math.Matrix

public class Matrix
extends java.lang.Object

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

- construction and getters/setters: `Matrix(double[][])`, `Matrix(int,int)`, `Matrix(Matrix)`, `get(int,int)`, `set(int,int, double)`, `equals(Object)`
- one-matrix operations: `transpose()`, `invert()`, `determinant()`
- two-matrix operations: `add(Matrix)`, `multiply(double)`, `multiply(Matrix)`,
- solve as system of equations: `solveGaussJordan(int)`, `maximize(double[])`

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(double[][] x)`
`Matrix(int rows, int cols)` Create a new matrix of the indicated number of m rows and columns.
`Matrix(Matrix m)` Create a new Matrix by copying (not sharing) the content of the one passed in.

Method Summary
`Matrix` | `add(Matrix x)` Return new matrix that is sum of this and passed matrix.
`double` | `determinant()` Return the determinant of the matrix.
`boolean` | `equals(java.lang.Object o)`
`double` | `get(int row, int col)`
`int` | `getCols()`
`int` | `getRows()`
`int` | `hashCode()`
`Matrix` | `invert()` 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.
`Matrix` | `multiply(double s)` Return new matrix that is result of multiplying each element by the scalar s.
`Matrix` | `multiply(Matrix x)` Return new matrix that is product of this and passed matrix.
`void` | `set(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.
`Matrix` | `transpose()` Return a new matrix that is the transpose of this one.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

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

### getRows

    public int getRows()

  Returns:
    number of rows in matrix

### getCols

    public int getCols()

  Returns:
    number of columns in matrix

### get

    public double get(int row,
                      int col)

### set

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

### equals

    public boolean equals(java.lang.Object o)

  Overrides:
    `equals` in class `java.lang.Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`

### transpose

    public Matrix transpose()

  Return a new matrix that is the transpose of this one.

### invert

    public Matrix invert()
                  throws java.lang.IllegalStateException

  Returns new matrix that is the inverse. Subsequently multiplying this matrix by its inverse yields an identity matrix.

  Throws:
    `java.lang.IllegalStateException` - if matrix is not invertable.

### determinant

    public double determinant()
                       throws java.lang.IllegalStateException

  Return the determinant of the matrix.

  Throws:
    `java.lang.IllegalStateException`

### add

    public Matrix add(Matrix x)
               throws java.lang.IllegalArgumentException

  Return new matrix that is sum of this and passed matrix. Matrices must have same dimensions.

  Throws:
    `java.lang.IllegalArgumentException` - if passed matrix is of different dimension.

### 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)
                    throws java.lang.IllegalArgumentException

  Return new matrix that is product of this and passed matrix.

  Throws:
    `java.lang.IllegalArgumentException` - if passed matrix is of different dimension.

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

### 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].

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Multivalent API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD