Class BigMatrixImpl
- All Implemented Interfaces:
Serializable
,AnyMatrix
,BigMatrix
BigMatrix
using a BigDecimal[][] 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 stored and reused on subsequent calls. If matrix
data are modified using any of the public setXxx methods, the saved
decomposition is discarded. 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 invokeLUDecompose()
to recompute the decomposition before using any of the methods above. -
As specified in the
BigMatrix
interface, matrix element indexing is 0-based -- e.g.,getEntry(0, 0)
returns the element in the first row, first column of the matrix.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Creates a matrix with no dataBigMatrixImpl
(double[][] d) Deprecated.Create a new BigMatrix usingd
as the underlying data array.BigMatrixImpl
(int rowDimension, int columnDimension) Deprecated.Create a new BigMatrix with the supplied row and column dimensions.BigMatrixImpl
(String[][] d) Deprecated.Create a new BigMatrix using the values represented by the strings ind
as the underlying data array.BigMatrixImpl
(BigDecimal[] v) Deprecated.Create a new (column) BigMatrix usingv
as the data for the unique column of thev.length x 1
matrix created.BigMatrixImpl
(BigDecimal[][] d) Deprecated.Create a new BigMatrix usingd
as the underlying data array.BigMatrixImpl
(BigDecimal[][] d, boolean copyArray) Deprecated.Create a new BigMatrix using the input array as the underlying data array. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Compute the sum of this andm
.add
(BigMatrixImpl m) Deprecated.Compute the sum of this andm
.copy()
Deprecated.Create a new BigMatrix which is a copy of this.boolean
Deprecated.Returns true iffobject
is aBigMatrixImpl
instance with the same dimensions as this and all corresponding matrix entries are equal.getColumn
(int col) Deprecated.Returns the entries in column numbercol
as an array.double[]
getColumnAsDoubleArray
(int col) Deprecated.Returns the entries in column numbercol
as an array of double values.int
Deprecated.Returns the number of columns in the matrix.getColumnMatrix
(int column) Deprecated.Returns the entries in column numbercolumn
as a column matrix.BigDecimal[][]
getData()
Deprecated.Returns matrix entries as a two-dimensional array.double[][]
Deprecated.Returns matrix entries as a two-dimensional array.BigDecimal[][]
Deprecated.Returns a reference to the underlying data array.Deprecated.Returns the determinant of this matrix.getEntry
(int row, int column) Deprecated.Returns the entry in the specified row and column.double
getEntryAsDouble
(int row, int column) Deprecated.Returns the entry in the specified row and column as a double.getNorm()
Deprecated.Returns the maximum absolute row sum norm of the matrix.int
Deprecated.Gets the rounding mode for division operations The default isBigDecimal.ROUND_HALF_UP
getRow
(int row) Deprecated.Returns the entries in row numberrow
as an array.double[]
getRowAsDoubleArray
(int row) Deprecated.Returns the entries in row numberrow
as an array of double values.int
Deprecated.Returns the number of rows in the matrix.getRowMatrix
(int row) Deprecated.Returns the entries in row numberrow
as a row matrix.int
getScale()
Deprecated.Sets the scale for division operations.getSubMatrix
(int[] selectedRows, int[] selectedColumns) Deprecated.Gets a submatrix.getSubMatrix
(int startRow, int endRow, int startColumn, int endColumn) Deprecated.Gets a submatrix.getTrace()
Deprecated.Returns the trace of the matrix (the sum of the elements on the main diagonal).int
hashCode()
Deprecated.Computes a hashcode for the matrix.inverse()
Deprecated.Returns the inverse matrix if this matrix is invertible.boolean
Deprecated.Is this a singular matrix?boolean
isSquare()
Deprecated.Is this a square matrix?void
Deprecated.Computes a new LU decompostion for this matrix, storing the result for use by other methods.Deprecated.Returns the result of postmultiplying this bym
.Deprecated.Returns the result of postmultiplying this bym
.operate
(double[] v) Deprecated.Returns the result of multiplying this by the vectorv
.operate
(BigDecimal[] v) Deprecated.Returns the result of multiplying this by the vectorv
.preMultiply
(BigDecimal[] v) Deprecated.Returns the (row) vector result of premultiplying this by the vectorv
.Deprecated.Returns the result premultiplying this bym
.Deprecated.Returns the result of adding d to each entry of this.Deprecated.Returns the result of multiplying each entry of this byd
void
setRoundingMode
(int roundingMode) Deprecated.Sets the rounding mode for decimal divisions.void
setScale
(int scale) Deprecated.Sets the scale for division operations.void
setSubMatrix
(BigDecimal[][] subMatrix, int row, int column) Deprecated.Replace the submatrix starting atrow, column
using data in the inputsubMatrix
array.solve
(double[] b) Deprecated.Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns ofb
.solve
(BigDecimal[] b) Deprecated.Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns ofb
.Deprecated.Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns ofb
.Deprecated.Compute this minusm
.Deprecated.Compute this minusm
.toString()
Deprecated.Get a string representation for this matrix.Deprecated.Returns the transpose matrix.
-
Constructor Details
-
BigMatrixImpl
public BigMatrixImpl()Deprecated.Creates a matrix with no data -
BigMatrixImpl
public BigMatrixImpl(int rowDimension, int columnDimension) Deprecated.Create a new BigMatrix with the supplied row and column dimensions.- Parameters:
rowDimension
- the number of rows in the new matrixcolumnDimension
- the number of columns in the new matrix- Throws:
IllegalArgumentException
- if row or column dimension is not positive
-
BigMatrixImpl
Deprecated.Create a new BigMatrix usingd
as the underlying data array.The input array is copied, not referenced. This constructor has the same effect as calling
BigMatrixImpl(BigDecimal[][], boolean)
with the second argument set totrue
.- Parameters:
d
- data for new matrix- Throws:
IllegalArgumentException
- ifd
is not rectangular (not all rows have the same length) or emptyNullPointerException
- ifd
is null
-
BigMatrixImpl
Deprecated.Create a new BigMatrix using the input array as the underlying data array.If an array is built specially in order to be embedded in a BigMatrix and not used directly, the
copyArray
may be set tofalseinvalid input: '<'/code. This will prevent the copying and improve performance as no new array will be built and no data will be copied.
- Parameters:
d
- data for new matrixcopyArray
- if true, the input array will be copied, otherwise it will be referenced- Throws:
IllegalArgumentException
- ifd
is not rectangular (not all rows have the same length) or emptyNullPointerException
- ifd
is null- See Also:
-
BigMatrixImpl
public BigMatrixImpl(double[][] d) Deprecated.Create a new BigMatrix usingd
as the underlying data array.Since the underlying array will hold
BigDecimal
instances, it will be created.- Parameters:
d
- data for new matrix- Throws:
IllegalArgumentException
- ifd
is not rectangular (not all rows have the same length) or emptyNullPointerException
- ifd
is null
-
BigMatrixImpl
Deprecated.Create a new BigMatrix using the values represented by the strings ind
as the underlying data array.- Parameters:
d
- data for new matrix- Throws:
IllegalArgumentException
- ifd
is not rectangular (not all rows have the same length) or emptyNullPointerException
- ifd
is null
-
BigMatrixImpl
Deprecated.Create a new (column) BigMatrix usingv
as the data for the unique column of thev.length x 1
matrix created.The input array is copied, not referenced.
- Parameters:
v
- column vector holding data for new matrix
-
-
Method Details
-
copy
Deprecated.Create a new BigMatrix which is a copy of this. -
add
Deprecated.Compute the sum of this andm
.- Specified by:
add
in interfaceBigMatrix
- Parameters:
m
- matrix to be added- Returns:
- this + m
- Throws:
IllegalArgumentException
- if m is not the same size as this
-
add
Deprecated.Compute the sum of this andm
.- Parameters:
m
- matrix to be added- Returns:
- this + m
- Throws:
IllegalArgumentException
- if m is not the same size as this
-
subtract
Deprecated.Compute this minusm
.- Specified by:
subtract
in interfaceBigMatrix
- Parameters:
m
- matrix to be subtracted- Returns:
- this + m
- Throws:
IllegalArgumentException
- if m is not the same size as this
-
subtract
Deprecated.Compute this minusm
.- Parameters:
m
- matrix to be subtracted- Returns:
- this + m
- Throws:
IllegalArgumentException
- if m is not the same size as this
-
scalarAdd
Deprecated.Returns the result of adding d to each entry of this. -
scalarMultiply
Deprecated.Returns the result of multiplying each entry of this byd
- Specified by:
scalarMultiply
in interfaceBigMatrix
- Parameters:
d
- value to multiply all entries by- Returns:
- d * this
-
multiply
Deprecated.Returns the result of postmultiplying this bym
.- Specified by:
multiply
in interfaceBigMatrix
- Parameters:
m
- matrix to postmultiply by- Returns:
- this*m
- Throws:
IllegalArgumentException
- if columnDimension(this) != rowDimension(m)
-
multiply
Deprecated.Returns the result of postmultiplying this bym
.- Parameters:
m
- matrix to postmultiply by- Returns:
- this*m
- Throws:
IllegalArgumentException
- if columnDimension(this) != rowDimension(m)
-
preMultiply
Deprecated.Returns the result premultiplying this bym
.- Specified by:
preMultiply
in interfaceBigMatrix
- Parameters:
m
- matrix to premultiply by- Returns:
- m * this
- Throws:
IllegalArgumentException
- if rowDimension(this) != columnDimension(m)
-
getData
Deprecated.Returns matrix entries as a two-dimensional array.Makes a fresh copy of the underlying data.
-
getDataAsDoubleArray
public double[][] getDataAsDoubleArray()Deprecated.Returns matrix entries as a two-dimensional array.Makes a fresh copy of the underlying data converted to
double
values.- Specified by:
getDataAsDoubleArray
in interfaceBigMatrix
- Returns:
- 2-dimensional array of entries
-
getDataRef
Deprecated.Returns a reference to the underlying data array.Does not make a fresh copy of the underlying data.
- Returns:
- 2-dimensional array of entries
-
getRoundingMode
public int getRoundingMode()Deprecated.Gets the rounding mode for division operations The default isBigDecimal.ROUND_HALF_UP
- Specified by:
getRoundingMode
in interfaceBigMatrix
- Returns:
- the rounding mode.
- See Also:
-
setRoundingMode
public void setRoundingMode(int roundingMode) Deprecated.Sets the rounding mode for decimal divisions.- Parameters:
roundingMode
- rounding mode for decimal divisions- See Also:
-
getScale
public int getScale()Deprecated.Sets the scale for division operations. The default is 64- Returns:
- the scale
- See Also:
-
setScale
public void setScale(int scale) Deprecated.Sets the scale for division operations.- Parameters:
scale
- scale for division operations- See Also:
-
getNorm
Deprecated.Returns the maximum absolute row sum norm of the matrix. -
getSubMatrix
public BigMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) throws MatrixIndexException Deprecated.Gets a submatrix. Rows and columns are indicated counting from 0 to n-1.- Specified by:
getSubMatrix
in interfaceBigMatrix
- Parameters:
startRow
- Initial row indexendRow
- Final row indexstartColumn
- Initial column indexendColumn
- Final column index- Returns:
- The subMatrix containing the data of the specified rows and columns
- Throws:
MatrixIndexException
- if row or column selections are not valid
-
getSubMatrix
public BigMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns) throws MatrixIndexException Deprecated.Gets a submatrix. Rows and columns are indicated counting from 0 to n-1.- Specified by:
getSubMatrix
in interfaceBigMatrix
- Parameters:
selectedRows
- Array of row indices must be non-emptyselectedColumns
- Array of column indices must be non-empty- Returns:
- The subMatrix containing the data in the specified rows and columns
- Throws:
MatrixIndexException
- if supplied row or column index arrays are not valid
-
setSubMatrix
Deprecated.Replace the submatrix starting atrow, column
using data in the inputsubMatrix
array. Indexes are 0-based.Example:
Starting with1 2 3 4 5 6 7 8 9 0 1 2
andsubMatrix = {{3, 4} {5,6}}
, invokingsetSubMatrix(subMatrix,1,1))
will result in1 2 3 4 5 3 4 8 9 5 6 2
- Parameters:
subMatrix
- array containing the submatrix replacement datarow
- row coordinate of the top, left element to be replacedcolumn
- 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)IllegalArgumentException
- ifsubMatrix
is not rectangular (not all rows have the same length) or emptyNullPointerException
- ifsubMatrix
is null- Since:
- 1.1
-
getRowMatrix
Deprecated.Returns the entries in row numberrow
as a row matrix. Row indices start at 0.- Specified by:
getRowMatrix
in interfaceBigMatrix
- Parameters:
row
- the row to be fetched- Returns:
- row matrix
- Throws:
MatrixIndexException
- if the specified row index is invalid
-
getColumnMatrix
Deprecated.Returns the entries in column numbercolumn
as a column matrix. Column indices start at 0.- Specified by:
getColumnMatrix
in interfaceBigMatrix
- Parameters:
column
- the column to be fetched- Returns:
- column matrix
- Throws:
MatrixIndexException
- if the specified column index is invalid
-
getRow
Deprecated.Returns the entries in row numberrow
as an array.Row indices start at 0. A
MatrixIndexException
is thrown unless0 invalid input: '<'= row invalid input: '<' rowDimension.
- Specified by:
getRow
in interfaceBigMatrix
- 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
Deprecated.Returns the entries in row numberrow
as an array of double values.Row indices start at 0. A
MatrixIndexException
is thrown unless0 invalid input: '<'= row invalid input: '<' rowDimension.
- Specified by:
getRowAsDoubleArray
in interfaceBigMatrix
- 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
Deprecated.Returns the entries in column numbercol
as an array.Column indices start at 0. A
MatrixIndexException
is thrown unless0 invalid input: '<'= column invalid input: '<' columnDimension.
- Specified by:
getColumn
in interfaceBigMatrix
- 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
Deprecated.Returns the entries in column numbercol
as an array of double values.Column indices start at 0. A
MatrixIndexException
is thrown unless0 invalid input: '<'= column invalid input: '<' columnDimension.
- Specified by:
getColumnAsDoubleArray
in interfaceBigMatrix
- 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
Deprecated.Returns the entry in the specified row and column.Row and column indices start at 0 and must satisfy
0 invalid input: '<'= row invalid input: '<' rowDimension
0 invalid input: '<'= column invalid input: '<' columnDimension
MatrixIndexException
is thrown.- Specified by:
getEntry
in interfaceBigMatrix
- Parameters:
row
- row location of entry to be fetchedcolumn
- 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
Deprecated.Returns the entry in the specified row and column as a double.Row and column indices start at 0 and must satisfy
0 invalid input: '<'= row invalid input: '<' rowDimension
0 invalid input: '<'= column invalid input: '<' columnDimension
MatrixIndexException
is thrown.- Specified by:
getEntryAsDouble
in interfaceBigMatrix
- Parameters:
row
- row location of entry to be fetchedcolumn
- 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
Deprecated.Returns the transpose matrix. -
inverse
Deprecated.Returns the inverse matrix if this matrix is invertible.- Specified by:
inverse
in interfaceBigMatrix
- Returns:
- inverse matrix
- Throws:
InvalidMatrixException
- if this is not invertible
-
getDeterminant
Deprecated.Returns the determinant of this matrix.- Specified by:
getDeterminant
in interfaceBigMatrix
- Returns:
- determinant
- Throws:
InvalidMatrixException
- if matrix is not square
-
isSquare
public boolean isSquare()Deprecated.Is this a square matrix? -
isSingular
public boolean isSingular()Deprecated.Is this a singular matrix?- Returns:
- true if the matrix is singular
-
getRowDimension
public int getRowDimension()Deprecated.Returns the number of rows in the matrix.- Specified by:
getRowDimension
in interfaceAnyMatrix
- Returns:
- rowDimension
-
getColumnDimension
public int getColumnDimension()Deprecated.Returns the number of columns in the matrix.- Specified by:
getColumnDimension
in interfaceAnyMatrix
- Returns:
- columnDimension
-
getTrace
Deprecated.Returns the trace of the matrix (the sum of the elements on the main diagonal).- Specified by:
getTrace
in interfaceBigMatrix
- Returns:
- trace
- Throws:
IllegalArgumentException
- if this matrix is not square.
-
operate
Deprecated.Returns the result of multiplying this by the vectorv
.- Specified by:
operate
in interfaceBigMatrix
- Parameters:
v
- the vector to operate on- Returns:
- this*v
- Throws:
IllegalArgumentException
- if columnDimension != v.size()
-
operate
Deprecated.Returns the result of multiplying this by the vectorv
.- Parameters:
v
- the vector to operate on- Returns:
- this*v
- Throws:
IllegalArgumentException
- if columnDimension != v.size()
-
preMultiply
Deprecated.Returns the (row) vector result of premultiplying this by the vectorv
.- Specified by:
preMultiply
in interfaceBigMatrix
- Parameters:
v
- the row vector to premultiply by- Returns:
- v*this
- Throws:
IllegalArgumentException
- if rowDimension != v.size()
-
solve
Deprecated.Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns ofb
.- Specified by:
solve
in interfaceBigMatrix
- Parameters:
b
- array of constants forming RHS of linear systems to to solve- Returns:
- solution array
- Throws:
IllegalArgumentException
- if this.rowDimension != row dimensionInvalidMatrixException
- if this matrix is not square or is singular
-
solve
Deprecated.Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns ofb
.- Parameters:
b
- array of constants forming RHS of linear systems to to solve- Returns:
- solution array
- Throws:
IllegalArgumentException
- if this.rowDimension != row dimensionInvalidMatrixException
- if this matrix is not square or is singular
-
solve
Deprecated.Returns a matrix of (column) solution vectors for linear systems with coefficient matrix = this and constant vectors = columns ofb
.- Specified by:
solve
in interfaceBigMatrix
- 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 dimensionInvalidMatrixException
- if this matrix is not square or is singular
-
luDecompose
Deprecated.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.
-
toString
Deprecated.Get a string representation for this matrix. -
equals
Deprecated.Returns true iffobject
is aBigMatrixImpl
instance with the same dimensions as this and all corresponding matrix entries are equal. BigDecimal.equals is used to compare corresponding entries. -
hashCode
public int hashCode()Deprecated.Computes a hashcode for the matrix.
-
Array2DRowFieldMatrix
with aBigReal
parameter