Class SquareMatrix<M extends SquareMatrix<M>>
- All Implemented Interfaces:
IArchive
- Direct Known Subclasses:
GenericSquareMatrix
,PhaseMatrix
,R2x2
,R3x3
,R4x4
,R6x6
Class SquareMatrix
is the abstract base class for square matrix
objects supported in the XAL tools packages.
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.
Currently the internal matrix operations are supported by the EJML matrix package.
- Since:
- Sep 25, 2013
- Author:
- Christopher K. Allen, Blaz Kranjc
-
Field Summary
Fields inherited from class xal.tools.math.BaseMatrix
ATTR_DATA, DBL_EPS, ULPS_BRACKET
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SquareMatrix
(double[][] arrVals) Initializing constructor for bases classSquareMatrix
.protected
SquareMatrix
(int intSize) Constructor for SquareMatrix.protected
SquareMatrix
(int intSize, 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 forSquareMatrix
.protected
SquareMatrix
(org.ejml.data.DenseMatrix64F mat) -
Method Summary
Modifier and TypeMethodDescriptionconjugateInv
(M matPhi) Function for inverse conjugation of this matrix by the argument matrix.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.boolean
Check if matrix is symmetric.<V extends BaseVector<V>>
Vsolve
(V vecObs) Solves the linear matrix-vector system without destroying the given data vector.<V extends BaseVector<V>>
voidsolveInPlace
(V vecObs) Solves the linear matrix-vector system and returns the solution in the given data vector.void
timesEquals
(BaseMatrix<M> matMult) Deprecated.Misleading name, this is not real matrix multiplication.double
trace()
Computes trace of the matrix.Methods inherited from class xal.tools.math.BaseMatrix
assignIdentity, assignMatrix, assignZero, clone, conditionNumber, copy, equals, getArrayCopy, getColCnt, getElem, getElem, getMatrix, getRowCnt, hashCode, inverse, isApproxEqual, isApproxEqual, isEquivalentTo, isSquare, load, max, minus, minusEquals, newInstance, newInstance, norm1, norm2, normF, normInf, plus, plusEquals, print, rank, save, setElem, setElem, setMatrix, setMatrix, setSubMatrix, times, times, times, timesEquals, toString, toStringMatrix, toStringMatrix, toStringMatrix, transpose
-
Constructor Details
-
SquareMatrix
Constructor for SquareMatrix. Creates a new, uninitialized instance of a square matrix with the given matrix dimensions. The matrix contains all zeros.- Parameters:
intSize
- size of this square matrix- Throws:
UnsupportedOperationException
- child class has not defined a public, zero-argument constructor- Since:
- Oct 14, 2013
-
SquareMatrix
Copy constructor forSquareMatrix
. Creates a deep copy of the given object. The dimensions are set and the internal array is cloned.- Parameters:
matParent
- the matrix to be cloned- Throws:
UnsupportedOperationException
- base class has not defined a public, zero-argument constructor- Since:
- Sep 25, 2013
-
SquareMatrix
Parsing Constructor - creates an instance of the child class and initialize it according to a token string of element values. The token string argument is assumed to be one-dimensional and packed by column (ala FORTRAN).- Parameters:
intSize
- the matrix size of this objectstrTokens
- token vector of getSize()^2 numeric values- Throws:
NumberFormatException
- bad number format, unparseable
-
SquareMatrix
Initializing constructor for bases class
SquareMatrix
. Sets the entire matrix to the values given in the Java primitive type double array. Warning! The argument becomes the internal matrix representation and, thus, is not immutable.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.
- Parameters:
arrVals
- Java primitive array containing new matrix values- Throws:
ArrayIndexOutOfBoundsException
- the argument must have the same dimensions as this matrixIllegalArgumentException
- the argument is degenerate, not fully allocated- Since:
- Oct 4, 2013
-
SquareMatrix
protected SquareMatrix(org.ejml.data.DenseMatrix64F mat) - See Also:
-
-
Method Details
-
getSize
public int getSize()Returns the size of this square matrix, that is, the equal number of rows and columns.- Returns:
- matrix is square of this size on a side
- Since:
- Sep 25, 2013
-
isSymmetric
public boolean isSymmetric()Check if matrix is symmetric.- Returns:
- true if matrix is symmetric
-
det
public double det()Matrix determinant function.- Returns:
- the determinant of this square matrix
-
solve
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.Note that the inverse matrix A-1 is never computed. 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.
- Parameters:
vecObs
- the data vector- Returns:
- vector which, when multiplied by this matrix, will equal the data vector
-
solveInPlace
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. 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.
- Parameters:
vecObs
- the data vector on call, the solution vector upon return- Since:
- Oct 11, 2013
-
trace
public double trace()Computes trace of the matrix.- Returns:
- Trace of the matrix.
-
timesEquals
Deprecated.Misleading name, this is not real matrix multiplication.In-place matrix element by element multiplication.- Parameters:
matMult
- Matrix providing the factors.
-
conjugateTrans
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
- Parameters:
matPhi
- conjugating matrix Φ (typically a transfer matrix)- Returns:
- matPhi*this*matPhi^T, or
null
if an error occurred
-
conjugateInv
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
- Parameters:
matPhi
- conjugating matrix Φ (typically a transfer matrix)- Returns:
- matPhi*this*matPhi-1
-