Class SquareMatrix<M extends SquareMatrix<M>>

java.lang.Object
xal.tools.math.BaseMatrix<M>
xal.tools.math.SquareMatrix<M>
All Implemented Interfaces:
IArchive
Direct Known Subclasses:
GenericSquareMatrix, PhaseMatrix, R2x2, R3x3, R4x4, R6x6

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.

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
  • Constructor Details

    • SquareMatrix

      protected SquareMatrix(int intSize) throws UnsupportedOperationException
      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

      protected SquareMatrix(M matParent) throws UnsupportedOperationException
      Copy constructor for SquareMatrix. 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

      protected SquareMatrix(int intSize, String strTokens) throws NumberFormatException
      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 object
      strTokens - token vector of getSize()^2 numeric values
      Throws:
      NumberFormatException - bad number format, unparseable
    • SquareMatrix

      protected SquareMatrix(double[][] arrVals) throws ArrayIndexOutOfBoundsException

      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 matrix
      IllegalArgumentException - 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

      public <V extends BaseVector<V>> V solve(V vecObs)

      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

      public <V extends BaseVector<V>> void solveInPlace(V vecObs)

      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 public void timesEquals(BaseMatrix<M> matMult)
      Deprecated.
      Misleading name, this is not real matrix multiplication.
      In-place matrix element by element multiplication.
      Parameters:
      matMult - Matrix providing the factors.
    • conjugateTrans

      public 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

      Parameters:
      matPhi - conjugating matrix Φ (typically a transfer matrix)
      Returns:
      matPhi*this*matPhi^T, or null if an error occurred
    • conjugateInv

      public 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

      Parameters:
      matPhi - conjugating matrix Φ (typically a transfer matrix)
      Returns:
      matPhi*this*matPhi-1