Class Rmxn

All Implemented Interfaces:
IArchive

public class Rmxn extends BaseMatrix<Rmxn>
Real matrix with arbitrary row and column dimensions. This class supports the usual matrix operations for non-square matrices but does not optimize for square matrices. Because general matrix dimensions must be considered there is more overhead when using this class over the specialized matrix classes.
Since:
Jul 21, 2015
Author:
Christopher K. Allen
  • Constructor Details

    • Rmxn

      public Rmxn(int cntRows, int cntCols)
      Zero-matrix constructor for class Rmxn. A matrix of the given dimension is created, all the elements are zero.
      Parameters:
      cntRows - number of matrix rows
      cntCols - number of matrix columns
      Since:
      Jul 21, 2015 by Christopher K. Allen
    • Rmxn

      public Rmxn(double[][] arrVals) throws ArrayIndexOutOfBoundsException

      Initializing constructor for class Rmxn. Initializes the matrix to the values given in the Java primitive type double array by setting the internal matrix representation to the given Java array. The matrix is shaped according to the (row-packed) argument.

      The dimensions of the given Java double array determine the size of the matrix. An mxn Java double array creates an mxn Rmxn array. If the argument is not fully allocated or inconsistent, an exception is thrown.

      As an example consider the following Java array

       
       double[][] arrInternal = new double[][] {
                                     {1.1, 1.2, 1.3, 1.4, 1.5},
                                     {2.1, 2.2, 2.3, 2.0, 2.5},
                                     {3.1, 3.2, 3.3, 3.4, 3.0}
                                      };
       
       
      This array would produce a 3×5 matrix. Note that the given argument becomes the internal representation of the matrix object. Thus, the Java array arrInternal will be changed by the the encapsulating matrix object so should no longer be referenced after presenting it to this constructor.

      Parameters:
      arrVals - Java primitive array to be new internal matrix value representation
      Throws:
      IllegalArgumentException - the argument is degenerate and cannot represent a matrix
      ArrayIndexOutOfBoundsException
      Since:
      Jul 21, 2015 by Christopher K. Allen
    • Rmxn

      public Rmxn(int cntRows, int cntCols, String strTokens) throws IllegalArgumentException, 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:
      cntRows - the matrix row size of this object
      cntCols - the matrix column size of this object
      strTokens - token vector of getSize()^2 numeric values
      Throws:
      IllegalArgumentException - wrong number of token strings
      NumberFormatException - bad number format, unparseable
      Since:
      Jul 21, 2015 by Christopher K. Allen
    • Rmxn

      public Rmxn(Rmxn matTemplate)
      Copy constructor for Rmxn. A new instance is created which is a deep copy of the given argument.
      Parameters:
      matTemplate - matrix to be cloned
      Since:
      Jul 21, 2015 by Christopher K. Allen
  • Method Details

    • newIdentity

      public static Rmxn newIdentity(int cntSize)
      Creates and returns a new instance of the identity matrix with the given dimensions.
      Parameters:
      cntSize - the size of the identity matrix (i.e., row and column count)
      Returns:
      Since:
      Jul 23, 2015 by Christopher K. Allen
    • plus

      public Rmxn plus(Rmxn matAddend)
      Description copied from class: BaseMatrix
      Non-destructive matrix addition. This matrix is unaffected.
      Overrides:
      plus in class BaseMatrix<Rmxn>
      Parameters:
      matAddend - matrix to be added to this
      Returns:
      the result of this matrix plus the given matrix (element-wise), or null if error
      Throws:
      IllegalArgumentException - Inconsistent matrix dimensions
      Since:
      Jul 22, 2015 by Christopher K. Allen
      See Also:
    • plusEquals

      public void plusEquals(Rmxn matAddend)
      Description copied from class: BaseMatrix
      In-place matrix addition. The given matrix is added to this matrix algebraically (element by element).
      Overrides:
      plusEquals in class BaseMatrix<Rmxn>
      Parameters:
      matAddend - matrix to be added to this (no new objects are created)
      Throws:
      IllegalArgumentException - Inconsistent matrix dimensions
      Since:
      Jul 22, 2015 by Christopher K. Allen
      See Also:
    • minus

      public Rmxn minus(Rmxn matSub)
      Description copied from class: BaseMatrix
      Non-destructive matrix subtraction. This matrix is unaffected.
      Overrides:
      minus in class BaseMatrix<Rmxn>
      Parameters:
      matSub - the subtrahend
      Returns:
      the value of this matrix minus the value of the given matrix, or null if an error occurred
      Throws:
      IllegalArgumentException - Inconsistent matrix dimensions
      Since:
      Jul 22, 2015 by Christopher K. Allen
      See Also:
    • minusEquals

      public void minusEquals(Rmxn matSub)
      Description copied from class: BaseMatrix
      In-place matrix subtraction. The given matrix is subtracted from the value of this matrix. No additional objects are created.
      Overrides:
      minusEquals in class BaseMatrix<Rmxn>
      Parameters:
      matSub - subtrahend
      Throws:
      IllegalArgumentException - Inconsistent matrix dimensions
      Since:
      Jul 22, 2015 by Christopher K. Allen
      See Also:
    • times

      public Rn times(Rn vecFac) throws 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.

      Parameters:
      vecFac - the vector factor
      Returns:
      the matrix-vector product of this matrix with the argument
      Throws:
      IllegalArgumentException - the argument vector must have compatible dimensions
      Since:
      Oct 11, 2013
    • clone

      public Rmxn clone()
      Description copied from class: BaseMatrix
      Base classes must override the clone operation in order to make deep copies of the current object. This operation cannot be done without the exact type.
      Specified by:
      clone in class BaseMatrix<Rmxn>
      Since:
      Jul 21, 2015 by Christopher K. Allen
      See Also:
    • newInstance

      protected Rmxn newInstance(int row, int col)
      Returns a new, zero element, instance of Rmxn which has the same dimensions as this object. That is, the returned object is in the same equivalence class of matrices as this one.
      Specified by:
      newInstance in class BaseMatrix<Rmxn>
      Parameters:
      row - Number of rows.
      col - Number of columns.
      Returns:
      uninitialized matrix object of type M
      Since:
      Jul 21, 2015 by Christopher K. Allen
      See Also:
      • xal.tools.math.BaseMatrix#newInstance()