org.apache.commons.math.linear
Interface BigMatrix

All Known Implementing Classes:
BigMatrixImpl

public interface BigMatrix

Interface defining a real-valued matrix with basic algebraic operations, using BigDecimal representations for the entries.

Matrix element indexing is 0-based -- e.g., getEntry(0, 0) returns the element in the first row, first column of the matrix.

Version:
$Revision: 1.9 $ $Date: 2004/10/25 03:12:28 $

Method Summary
 BigMatrix add(BigMatrix m)
          Compute the sum of this and m.
 BigMatrix copy()
          Returns a (deep) copy of this.
 BigDecimal[] getColumn(int col)
          Returns the entries in column number col as an array.
 double[] getColumnAsDoubleArray(int col)
          Returns the entries in column number col as an array of double values.
 int getColumnDimension()
          Returns the number of columns in the matrix.
 BigMatrix getColumnMatrix(int column)
          Returns the entries in column number column as a column matrix.
 BigDecimal[][] getData()
          Returns matrix entries as a two-dimensional array.
 double[][] getDataAsDoubleArray()
          Returns matrix entries as a two-dimensional array.
 BigDecimal getDeterminant()
          Returns the determinant of this matrix.
 BigDecimal getEntry(int row, int column)
          Returns the entry in the specified row and column.
 double getEntryAsDouble(int row, int column)
          Returns the entry in the specified row and column as a double.
 BigDecimal getNorm()
          Returns the maximum absolute row sum norm of the matrix.
 int getRoundingMode()
          Gets the rounding mode
 BigDecimal[] getRow(int row)
          Returns the entries in row number row as an array.
 double[] getRowAsDoubleArray(int row)
          Returns the entries in row number row as an array of double values.
 int getRowDimension()
          Returns the number of rows in the matrix.
 BigMatrix getRowMatrix(int row)
          Returns the entries in row number row as a row matrix.
 BigMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
          Gets a submatrix.
 BigMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
          Gets a submatrix.
 BigDecimal getTrace()
          Returns the trace of the matrix (the sum of the elements on the main diagonal).
 BigMatrix inverse()
          Returns the inverse of this matrix.
 boolean isSingular()
          Is this a singular matrix?
 boolean isSquare()
          Is this a square matrix?
 BigMatrix multiply(BigMatrix m)
          Returns the result of postmultiplying this by m.
 BigDecimal[] operate(BigDecimal[] v)
          Returns the result of multiplying this by the vector v.
 BigDecimal[] preMultiply(BigDecimal[] v)
          Returns the (row) vector result of premultiplying this by the vector v.
 BigMatrix preMultiply(BigMatrix m)
          Returns the result premultiplying this by m.
 BigMatrix scalarAdd(BigDecimal d)
          Returns the result of adding d to each entry of this.
 BigMatrix scalarMultiply(BigDecimal d)
          Returns the result multiplying each entry of this by d.
 BigDecimal[] solve(BigDecimal[] b)
          Returns the solution vector for a linear system with coefficient matrix = this and constant vector = b.
 BigMatrix solve(BigMatrix b)
          Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns of b.
 BigMatrix subtract(BigMatrix m)
          Compute this minus m.
 BigMatrix transpose()
          Returns the transpose of this matrix.
 

Method Detail

copy

public BigMatrix copy()
Returns a (deep) copy of this.

Returns:
matrix copy

add

public BigMatrix add(BigMatrix m)
              throws IllegalArgumentException
Compute the sum of this and m.

Parameters:
m - matrix to be added
Returns:
this + m
Throws:
IllegalArgumentException - if m is not the same size as this

subtract

public BigMatrix subtract(BigMatrix m)
                   throws IllegalArgumentException
Compute this minus m.

Parameters:
m - matrix to be subtracted
Returns:
this + m
Throws:
IllegalArgumentException - if m is not the same size as this

scalarAdd

public BigMatrix scalarAdd(BigDecimal d)
Returns the result of adding d to each entry of this.

Parameters:
d - value to be added to each entry
Returns:
d + this

scalarMultiply

public BigMatrix scalarMultiply(BigDecimal d)
Returns the result multiplying each entry of this by d.

Parameters:
d - value to multiply all entries by
Returns:
d * this

multiply

public BigMatrix multiply(BigMatrix m)
                   throws IllegalArgumentException
Returns the result of postmultiplying this by m.

Parameters:
m - matrix to postmultiply by
Returns:
this * m
Throws:
IllegalArgumentException - if columnDimension(this) != rowDimension(m)

preMultiply

public BigMatrix preMultiply(BigMatrix m)
                      throws IllegalArgumentException
Returns the result premultiplying this by m.

Parameters:
m - matrix to premultiply by
Returns:
m * this
Throws:
IllegalArgumentException - if rowDimension(this) != columnDimension(m)

getData

public BigDecimal[][] getData()
Returns matrix entries as a two-dimensional array.

Returns:
2-dimensional array of entries

getDataAsDoubleArray

public double[][] getDataAsDoubleArray()
Returns matrix entries as a two-dimensional array.

Returns:
2-dimensional array of entries

getRoundingMode

public int getRoundingMode()
Gets the rounding mode

Returns:
the rounding mode

getNorm

public BigDecimal getNorm()
Returns the maximum absolute row sum norm of the matrix.

Returns:
norm

getSubMatrix

public BigMatrix getSubMatrix(int startRow,
                              int endRow,
                              int startColumn,
                              int endColumn)
                       throws MatrixIndexException
Gets a submatrix. Rows and columns are indicated counting from 0 to n-1.

Parameters:
startRow - Initial row index
endRow - Final row index
startColumn - Initial column index
endColumn - Final column index
Returns:
The subMatrix containing the data of the specified rows and columns
Throws:
MatrixIndexException - if the indices are not valid

getSubMatrix

public BigMatrix getSubMatrix(int[] selectedRows,
                              int[] selectedColumns)
                       throws MatrixIndexException
Gets a submatrix. Rows and columns are indicated counting from 0 to n-1.

Parameters:
selectedRows - Array of row indices.
selectedColumns - Array of column indices.
Returns:
The subMatrix containing the data in the specified rows and columns
Throws:
MatrixIndexException - if row or column selections are not valid

getRowMatrix

public BigMatrix getRowMatrix(int row)
                       throws MatrixIndexException
Returns the entries in row number row as a row matrix. Row indices start at 0.

Parameters:
row - the row to be fetched
Returns:
row matrix
Throws:
MatrixIndexException - if the specified row index is invalid

getColumnMatrix

public BigMatrix getColumnMatrix(int column)
                          throws MatrixIndexException
Returns the entries in column number column as a column matrix. Column indices start at 0.

Parameters:
column - the column to be fetched
Returns:
column matrix
Throws:
MatrixIndexException - if the specified column index is invalid

getRow

public BigDecimal[] getRow(int row)
                    throws MatrixIndexException
Returns the entries in row number row as an array.

Row indices start at 0. A MatrixIndexException is thrown unless 0 <= row < rowDimension.

Parameters:
row - the row to be fetched
Returns:
array of entries in the row
Throws:
MatrixIndexException - if the specified row index is not valid

getRowAsDoubleArray

public double[] getRowAsDoubleArray(int row)
                             throws MatrixIndexException
Returns the entries in row number row as an array of double values.

Row indices start at 0. A MatrixIndexException is thrown unless 0 <= row < rowDimension.

Parameters:
row - the row to be fetched
Returns:
array of entries in the row
Throws:
MatrixIndexException - if the specified row index is not valid

getColumn

public BigDecimal[] getColumn(int col)
                       throws MatrixIndexException
Returns the entries in column number col as an array.

Column indices start at 0. A MatrixIndexException is thrown unless 0 <= column < columnDimension.

Parameters:
col - the column to be fetched
Returns:
array of entries in the column
Throws:
MatrixIndexException - if the specified column index is not valid

getColumnAsDoubleArray

public double[] getColumnAsDoubleArray(int col)
                                throws MatrixIndexException
Returns the entries in column number col as an array of double values.

Column indices start at 0. A MatrixIndexException is thrown unless 0 <= column < columnDimension.

Parameters:
col - the column to be fetched
Returns:
array of entries in the column
Throws:
MatrixIndexException - if the specified column index is not valid

getEntry

public BigDecimal getEntry(int row,
                           int column)
                    throws MatrixIndexException
Returns the entry in the specified row and column.

Row and column indices start at 0 and must satisfy

otherwise a MatrixIndexException is thrown.

Parameters:
row - row location of entry to be fetched
column - column location of entry to be fetched
Returns:
matrix entry in row,column
Throws:
MatrixIndexException - if the row or column index is not valid

getEntryAsDouble

public double getEntryAsDouble(int row,
                               int column)
                        throws MatrixIndexException
Returns the entry in the specified row and column as a double.

Row and column indices start at 0 and must satisfy

otherwise a MatrixIndexException is thrown.

Parameters:
row - row location of entry to be fetched
column - column location of entry to be fetched
Returns:
matrix entry in row,column
Throws:
MatrixIndexException - if the row or column index is not valid

transpose

public BigMatrix transpose()
Returns the transpose of this matrix.

Returns:
transpose matrix

inverse

public BigMatrix inverse()
                  throws InvalidMatrixException
Returns the inverse of this matrix.

Returns:
inverse matrix
Throws:
InvalidMatrixException - if this is not invertible

getDeterminant

public BigDecimal getDeterminant()
                          throws InvalidMatrixException
Returns the determinant of this matrix.

Returns:
determinant
Throws:
InvalidMatrixException - if matrix is not square

isSquare

public boolean isSquare()
Is this a square matrix?

Returns:
true if the matrix is square (rowDimension = columnDimension)

isSingular

public boolean isSingular()
Is this a singular matrix?

Returns:
true if the matrix is singular

getRowDimension

public int getRowDimension()
Returns the number of rows in the matrix.

Returns:
rowDimension

getColumnDimension

public int getColumnDimension()
Returns the number of columns in the matrix.

Returns:
columnDimension

getTrace

public BigDecimal getTrace()
Returns the trace of the matrix (the sum of the elements on the main diagonal).

Returns:
trace

operate

public BigDecimal[] operate(BigDecimal[] v)
                     throws IllegalArgumentException
Returns the result of multiplying this by the vector v.

Parameters:
v - the vector to operate on
Returns:
this*v
Throws:
IllegalArgumentException - if columnDimension != v.size()

preMultiply

public BigDecimal[] preMultiply(BigDecimal[] v)
                         throws IllegalArgumentException
Returns the (row) vector result of premultiplying this by the vector v.

Parameters:
v - the row vector to premultiply by
Returns:
v*this
Throws:
IllegalArgumentException - if rowDimension != v.size()

solve

public BigDecimal[] solve(BigDecimal[] b)
                   throws IllegalArgumentException,
                          InvalidMatrixException
Returns the solution vector for a linear system with coefficient matrix = this and constant vector = b.

Parameters:
b - constant vector
Returns:
vector of solution values to AX = b, where A is *this
Throws:
IllegalArgumentException - if this.rowDimension != b.length
InvalidMatrixException - if this matrix is not square or is singular

solve

public BigMatrix solve(BigMatrix b)
                throws IllegalArgumentException,
                       InvalidMatrixException
Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns of b.

Parameters:
b - matrix of constant vectors forming RHS of linear systems to to solve
Returns:
matrix of solution vectors
Throws:
IllegalArgumentException - if this.rowDimension != row dimension
InvalidMatrixException - if this matrix is not square or is singular


Copyright © 2003-2004 The Apache Software Foundation. All Rights Reserved.