| java.lang.Object org.apache.commons.math.linear.RealMatrixImpl
RealMatrixImpl | public class RealMatrixImpl implements RealMatrix,Serializable(Code) | | Implementation of RealMatrix using a double[][] array to store entries and
LU decompostion to support linear system
solution and inverse.
The LU decompostion is performed as needed, to support the following operations:
- solve
- isSingular
- getDeterminant
- inverse
Usage notes:
-
The LU decomposition is cached and reused on subsequent calls.
If data are modified via references to the underlying array obtained using
getDataRef() , then the stored LU decomposition will not be
discarded. In this case, you need to explicitly invoke
LUDecompose() to recompute the decomposition
before using any of the methods above.
-
As specified in the
RealMatrix interface, 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: 355770 $ $Date: 2005-12-10 12:48:57 -0700 (Sat, 10 Dec 2005) $ |
Field Summary | |
protected static double | TOO_SMALL |
Constructor Summary | |
public | RealMatrixImpl() | public | RealMatrixImpl(int rowDimension, int columnDimension) Create a new RealMatrix with the supplied row and column dimensions. | public | RealMatrixImpl(double[][] d) Create a new RealMatrix using the input array as the underlying
data array. | public | RealMatrixImpl(double[] v) Create a new (column) RealMatrix using v as the
data for the unique column of the v.length x 1 matrix
created. |
Method Summary | |
public RealMatrix | add(RealMatrix m) Compute the sum of this and m . | public RealMatrix | copy() Create a new RealMatrix which is a copy of this. | public boolean | equals(Object object) Returns true iff object is a
RealMatrixImpl instance with the same dimensions as this
and all corresponding matrix entries are equal. | public double[] | getColumn(int col) Returns the entries in column number col as an array.
Column indices start at 0. | public int | getColumnDimension() | public RealMatrix | getColumnMatrix(int column) Returns the entries in column number column
as a column matrix. | public double[][] | getData() Returns matrix entries as a two-dimensional array. | public double[][] | getDataRef() Returns a reference to the underlying data array. | public double | getDeterminant() | public double | getEntry(int row, int column) Returns the entry in the specified row and column. | protected RealMatrix | getIdentity(int dimension) Returns dimension x dimension identity matrix. | protected RealMatrix | getLUMatrix() Returns the LU decomposition as a RealMatrix. | public double | getNorm() | protected int[] | getPermutation() Returns the permutation associated with the lu decomposition.
The entries of the array represent a permutation of the numbers 0, ... | public double[] | getRow(int row) Returns the entries in row number row as an array.
Row indices start at 0. | public int | getRowDimension() | public RealMatrix | getRowMatrix(int row) Returns the entries in row number row as a row matrix. | public RealMatrix | getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) Gets a submatrix. | public RealMatrix | getSubMatrix(int[] selectedRows, int[] selectedColumns) Gets a submatrix. | public double | getTrace() | public int | hashCode() Computes a hashcode for the matrix. | public RealMatrix | inverse() Returns the inverse matrix if this matrix is invertible. | public boolean | isSingular() | public boolean | isSquare() | public void | luDecompose() Computes a new
LU decompostion for this matrix, storing the result for use by other methods.
Implementation Note:
Uses
Crout's algortithm, with partial pivoting.
Usage Note:
This method should rarely be invoked directly. | public RealMatrix | multiply(RealMatrix m) Returns the result of postmultiplying this by m . | public double[] | operate(double[] v) | public RealMatrix | preMultiply(RealMatrix m) Returns the result premultiplying this by m . | public double[] | preMultiply(double[] v) | public RealMatrix | scalarAdd(double d) Returns the result of adding d to each entry of this. | public RealMatrix | scalarMultiply(double d) | public void | setSubMatrix(double[][] subMatrix, int row, int column) Replace the submatrix starting at row, column using data in
the input subMatrix array. | public double[] | solve(double[] b) Returns a matrix of (column) solution vectors for linear systems with
coefficient matrix = this and constant vectors = columns of
b . | public RealMatrix | solve(RealMatrix b) Returns a matrix of (column) solution vectors for linear systems with
coefficient matrix = this and constant vectors = columns of
b . | public RealMatrix | subtract(RealMatrix m) Compute this minus m . | public String | toString() | public RealMatrix | transpose() Returns the transpose matrix. |
TOO_SMALL | protected static double TOO_SMALL(Code) | | Bound to determine effective singularity in LU decomposition
|
RealMatrixImpl | public RealMatrixImpl()(Code) | | Creates a matrix with no data
|
RealMatrixImpl | public RealMatrixImpl(int rowDimension, int columnDimension)(Code) | | Create a new RealMatrix with the supplied row and column dimensions.
Parameters: rowDimension - the number of rows in the new matrix Parameters: columnDimension - the number of columns in the new matrix throws: IllegalArgumentException - if row or column dimension is notpositive |
RealMatrixImpl | public RealMatrixImpl(double[][] d)(Code) | | Create a new RealMatrix using the input array as the underlying
data array.
The input array is copied, not referenced.
Parameters: d - data for new matrix throws: IllegalArgumentException - if data is not rectangular(not all rows have the same length) or empty throws: NullPointerException - if data is null |
RealMatrixImpl | public RealMatrixImpl(double[] v)(Code) | | Create a new (column) RealMatrix using v as the
data for the unique column of the v.length x 1 matrix
created.
The input array is copied, not referenced.
Parameters: v - column vector holding data for new matrix |
copy | public RealMatrix copy()(Code) | | Create a new RealMatrix which is a copy of this.
the cloned matrix |
equals | public boolean equals(Object object)(Code) | | Returns true iff object is a
RealMatrixImpl instance with the same dimensions as this
and all corresponding matrix entries are equal. Corresponding entries
are compared using
java.lang.Double.doubleToLongBits(double) Parameters: object - the object to test equality against. true if object equals this |
getColumn | public double[] getColumn(int col) throws MatrixIndexException(Code) | | 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 array of entries in the column throws: MatrixIndexException - if the specified column index is not valid |
getColumnDimension | public int getColumnDimension()(Code) | | columnDimension |
getColumnMatrix | public RealMatrix getColumnMatrix(int column) throws MatrixIndexException(Code) | | Returns the entries in column number column
as a column matrix. Column indices start at 0.
Parameters: column - the column to be fetched column matrix throws: MatrixIndexException - if the specified column index is invalid |
getData | public double[][] getData()(Code) | | Returns matrix entries as a two-dimensional array.
Makes a fresh copy of the underlying data.
2-dimensional array of entries |
getDataRef | public double[][] getDataRef()(Code) | | Returns a reference to the underlying data array.
Does not make a fresh copy of the underlying data.
2-dimensional array of entries |
getEntry | public double getEntry(int row, int column) throws MatrixIndexException(Code) | | Returns the entry in the specified row and column.
Row and column indices start at 0 and must satisfy
0 <= row < rowDimension
0 <= column < columnDimension
otherwise a MatrixIndexException is thrown.
Parameters: row - row location of entry to be fetched Parameters: column - column location of entry to be fetched matrix entry in row,column throws: MatrixIndexException - if the row or column index is not valid |
getLUMatrix | protected RealMatrix getLUMatrix() throws InvalidMatrixException(Code) | | Returns the LU decomposition as a RealMatrix.
Returns a fresh copy of the cached LU matrix if this has been computed;
otherwise the composition is computed and cached for use by other methods.
Since a copy is returned in either case, changes to the returned matrix do not
affect the LU decomposition property.
The matrix returned is a compact representation of the LU decomposition.
Elements below the main diagonal correspond to entries of the "L" matrix;
elements on and above the main diagonal correspond to entries of the "U"
matrix.
Example:
Returned matrix L U
2 3 1 1 0 0 2 3 1
5 4 6 5 1 0 0 4 6
1 7 8 1 7 1 0 0 8
The L and U matrices satisfy the matrix equation LU = permuteRows(this),
where permuteRows reorders the rows of the matrix to follow the order determined
by the permutation property.
LU decomposition matrix throws: InvalidMatrixException - if the matrix is non-square or singular. |
getNorm | public double getNorm()(Code) | | norm |
getPermutation | protected int[] getPermutation()(Code) | | Returns the permutation associated with the lu decomposition.
The entries of the array represent a permutation of the numbers 0, ... , nRows - 1.
Example:
permutation = [1, 2, 0] means current 2nd row is first, current third row is second
and current first row is last.
Returns a fresh copy of the array.
the permutation |
getRow | public double[] getRow(int row) throws MatrixIndexException(Code) | | 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 array of entries in the row throws: MatrixIndexException - if the specified row index is not valid |
getRowDimension | public int getRowDimension()(Code) | | rowDimension |
getRowMatrix | public RealMatrix getRowMatrix(int row) throws MatrixIndexException(Code) | | Returns the entries in row number row as a row matrix.
Row indices start at 0.
Parameters: row - the row to be fetched row matrix throws: MatrixIndexException - if the specified row index is invalid |
getSubMatrix | public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) throws MatrixIndexException(Code) | | Gets a submatrix. Rows and columns are indicated
counting from 0 to n-1.
Parameters: startRow - Initial row index Parameters: endRow - Final row index Parameters: startColumn - Initial column index Parameters: endColumn - Final column index The subMatrix containing the data of thespecified rows and columns exception: MatrixIndexException - if row or column selections are not valid |
getSubMatrix | public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns) throws MatrixIndexException(Code) | | Gets a submatrix. Rows and columns are indicated
counting from 0 to n-1.
Parameters: selectedRows - Array of row indices must be non-empty Parameters: selectedColumns - Array of column indices must be non-empty The subMatrix containing the data in thespecified rows and columns exception: MatrixIndexException - if supplied row or column index arraysare not valid |
hashCode | public int hashCode()(Code) | | Computes a hashcode for the matrix.
hashcode for matrix |
isSingular | public boolean isSingular()(Code) | | true if the matrix is singular |
isSquare | public boolean isSquare()(Code) | | true if the matrix is square (rowDimension = columnDimension) |
luDecompose | public void luDecompose() throws InvalidMatrixException(Code) | | Computes a new
LU decompostion for this matrix, storing the result for use by other methods.
Implementation Note:
Uses
Crout's algortithm, with partial pivoting.
Usage Note:
This method should rarely be invoked directly. Its only use is
to force recomputation of the LU decomposition when changes have been
made to the underlying data using direct array references. Changes
made using setXxx methods will trigger recomputation when needed
automatically.
throws: InvalidMatrixException - if the matrix is non-square or singular. |
scalarAdd | public RealMatrix scalarAdd(double d)(Code) | | Returns the result of adding d to each entry of this.
Parameters: d - value to be added to each entry d + this |
scalarMultiply | public RealMatrix scalarMultiply(double d)(Code) | | Returns the result multiplying each entry of this by d
Parameters: d - value to multiply all entries by d * this |
setSubMatrix | public void setSubMatrix(double[][] subMatrix, int row, int column) throws MatrixIndexException(Code) | | Replace the submatrix starting at row, column using data in
the input subMatrix array. Indexes are 0-based.
Example:
Starting with
1 2 3 4
5 6 7 8
9 0 1 2
and subMatrix = {{3, 4} {5,6}} , invoking
setSubMatrix(subMatrix,1,1)) will result in
1 2 3 4
5 3 4 8
9 5 6 2
Parameters: subMatrix - array containing the submatrix replacement data Parameters: row - row coordinate of the top, left element to be replaced Parameters: column - column coordinate of the top, left element to be replaced throws: MatrixIndexException - if subMatrix does not fit into this matrix from element in (row, column) throws: IllegalArgumentException - if subMatrix is not rectangular(not all rows have the same length) or empty throws: NullPointerException - if subMatrix is null since: 1.1 |
transpose | public RealMatrix transpose()(Code) | | Returns the transpose matrix.
transpose matrix |
|
|