public abstract class SquareMatrix<M extends SquareMatrix<M>> extends BaseMatrix<M>
Class SquareMatrix
is the abstract base class for square matrix
objects supported in the XAL tools packages.
Currently the internal matrix operations are supported by the Jama matrix package. However, the Jama matrix package has been deemed a "proof of principle" for the Java language and scientific computing and is, thus, no longer supported. The objective of this base class is to hide the internal implementation of matrix operations from the child classes and all developers using the matrix packages. If it is determined that the Jama matrix package is to be removed from XAL, the modification will be substantially simplified in the current architecture.
ATTR_DATA, matImpl
Modifier | Constructor and Description |
---|---|
protected |
SquareMatrix(int intSize)
Constructor for SquareMatrix.
|
protected |
SquareMatrix(int intSize,
double[][] arrVals)
Initializing constructor for bases class
SquareMatrix . |
protected |
SquareMatrix(int intSize,
java.lang.String strTokens)
Parsing Constructor - creates an instance of the child class and initialize it
according to a token string of element values.
|
protected |
SquareMatrix(M matParent)
Copy constructor for
SquareMatrix . |
Modifier and Type | Method and Description |
---|---|
void |
assignIdentity()
Assign this matrix to be the identity matrix.
|
M |
conjugateInv(M matPhi)
Function for inverse conjugation of this matrix by the argument matrix.
|
M |
conjugateTrans(M matPhi)
Function for transpose conjugation of this matrix by the argument matrix.
|
double |
det()
Matrix determinant function.
|
int |
getSize()
Returns the size of this square matrix, that is, the equal
number of rows and columns.
|
M |
inverse()
Non-destructive inverse of this matrix.
|
boolean |
isEquivalentTo(BaseMatrix<M> matTest)
Checks if the given matrix is algebraically equivalent to this
matrix.
|
boolean |
isSymmetric()
Check if matrix is symmetric.
|
void |
setElem(IIndex iRow,
IIndex iCol,
double dblVal)
Set the element specified by the given position indices to the
given new value.
|
<V extends BaseVector<V>> |
solve(V vecObs)
Solves the linear matrix-vector system without destroying the given
data vector.
|
<V extends BaseVector<V>> |
solveInPlace(V vecObs)
Solves the linear matrix-vector system and returns the solution in
the given data vector.
|
M |
times(double s)
Non-destructive scalar multiplication.
|
M |
times(M matRight)
Non-destructive matrix multiplication.
|
<V extends BaseVector<V>> |
times(V vecFac)
Non-destructive matrix-vector multiplication.
|
void |
timesEquals(BaseMatrix<M> matMult)
In-place matrix multiplication.
|
void |
timesEquals(double s)
In-place scalar multiplication.
|
M |
transpose()
Non-destructive transpose of this matrix.
|
assignMatrix, assignZero, clone, conditionNumber, copy, equals, getArrayCopy, getColCnt, getElem, getElem, getMatrix, getRowCnt, hashCode, load, max, minus, minusEquals, newInstance, newInstance, norm1, norm2, normF, normInf, plus, plusEquals, print, save, setElem, setMatrix, setMatrix, setSubMatrix, toString, toStringMatrix, toStringMatrix, toStringMatrix
protected SquareMatrix(int intSize) throws java.lang.UnsupportedOperationException
intSize
- size of this square matrixjava.lang.UnsupportedOperationException
- child class has not defined a public, zero-argument constructorprotected SquareMatrix(M matParent) throws java.lang.UnsupportedOperationException
SquareMatrix
. Creates a deep
copy of the given object. The dimensions are set and the
internal array is cloned.matParent
- the matrix to be clonedjava.lang.UnsupportedOperationException
- base class has not defined a public, zero-argument constructorprotected SquareMatrix(int intSize, java.lang.String strTokens) throws java.lang.IllegalArgumentException, java.lang.NumberFormatException
intSize
- the matrix size of this objectstrTokens
- token vector of getSize()^2 numeric valuesjava.lang.IllegalArgumentException
- wrong number of token stringsjava.lang.NumberFormatException
- bad number format, unparseableprotected SquareMatrix(int intSize, double[][] arrVals) throws java.lang.ArrayIndexOutOfBoundsException
Initializing constructor for bases class SquareMatrix
.
Sets the entire matrix to the values given in the Java primitive type
double array. The argument itself remains unchanged.
The dimensions of the given Java double array must be consistent with the size of the matrix. Thus, if the arguments are inconsistent, an exception is thrown.
cntRows
- the matrix row size of this objectcntCols
- the matrix column size of this objectarrMatrix
- Java primitive array containing new matrix valuesjava.lang.ArrayIndexOutOfBoundsException
- the argument must have the same dimensions as this matrixpublic void setElem(IIndex iRow, IIndex iCol, double dblVal)
iRow
- matrix row locationiCol
- matrix column indexdblVal
- matrix element at given row and column will be set to this valuepublic void assignIdentity()
public int getSize()
public boolean isSymmetric()
public boolean isEquivalentTo(BaseMatrix<M> matTest)
matTest
- matrix under equivalency testtrue
if the argument is equivalent to this matrix,
false
if otherwisepublic M transpose()
null
if errorpublic double det()
public M inverse()
null
if errorpublic <V extends BaseVector<V>> V solve(V vecObs) throws java.lang.IllegalArgumentException
Solves the linear matrix-vector system without destroying the given
data vector. Say the linear system can be represented algebraically
as
Ax = y ,
where A is this matrix, x is the solution matrix to be
determined, and y is the data vector provided as the argument.
The returned value is equivalent to
x = A-1y ,
that is, the value of vector x.
The vector y is left unchanged. However, this is somewhat expensive in that the solution vector must be created through reflection and exceptions may occur. For a safer implementation, but where the solution is returned within the existing data vector y see
solveInPlace(BaseVector)
.
Note that the inverse matrix A-1 is never computed, the system is solved in less than N2 time. However, if this system is to be solved repeated for the same matrix A it may be preferable to invert this matrix and solve the multiple system with matrix multiplication.
vecObs
- the data vectorjava.lang.IllegalArgumentException
- the argument has the wrong sizepublic <V extends BaseVector<V>> void solveInPlace(V vecObs) throws java.lang.IllegalArgumentException
Solves the linear matrix-vector system and returns the solution in
the given data vector. Say the linear system can be represented
algebraically as
Ax = y ,
where A is this matrix, x is the solution matrix to be
determined, and y is the data vector provided as the argument.
The returned value is equivalent to
x = A-1y ,
that is, the value of vector y.
The value of x is returned within the argument vector. Thus, the argument cannot be immutable.
Note that the inverse matrix A-1 is never computed, the system is solved in less than N2 time. However, if this system is to be solved repeated for the same matrix A it may be preferable to invert this matrix and solve the multiple system with matrix multiplication.
vecObs
- the data vector on call, the solution vector upon returnjava.lang.IllegalArgumentException
- the argument has the wrong sizepublic M times(double s)
s
- multipliernull
if an error occurredpublic void timesEquals(double s)
s
- multiplierpublic <V extends BaseVector<V>> V times(V vecFac) throws java.lang.IllegalArgumentException
Non-destructive matrix-vector multiplication. The returned value is the
usual product of the given vector pre-multiplied by this matrix. Specifically,
denote by A this matrix and by x the argument vector, then
the components {yi} of the returned vector y are given by
yi = Σj Aijxj
The returned vector must be created using Java reflection, so this operation is somewhat more risky and expensive than and in place multiplication.
vecFac
- the vector factorjava.lang.IllegalArgumentException
- the argument vector must be the same sizepublic M times(M matRight)
matRight
- multiplicand - right operand of matrix multiplication operatornull
if an error occurredpublic void timesEquals(BaseMatrix<M> matMult)
matMult
- multiplicand - right operand of matrix multiplication operatorpublic M conjugateTrans(M matPhi)
Function for transpose conjugation of this matrix by the argument matrix. This method is non-destructive, returning a new matrix.
Denote by σ0 this matrix object, and denote
the argument matrix as Φ. Then the returned matrix,
σ1 is given by
σ1 = Φσ0ΦT
matPhi
- conjugating matrix Φ (typically a transfer matrix)null
if an error occurredpublic M conjugateInv(M matPhi)
Function for inverse conjugation of this matrix by the argument matrix. This method is non-destructive, return a new matrix.
Denote by σ0 this matrix object, and denote
the argument matrix as Φ. Then the returned matrix,
σ1 is given by
σ1 = Φσ0Φ-1
matPhi
- conjugating matrix Φ (typically a transfer matrix)