Class ElementaryOperation

  • All Implemented Interfaces:
    MatrixAccess, MatrixTable, Table

    public class ElementaryOperation
    extends Object
    implements MatrixTable
    There are three elementary row operations which are equivalent to left multiplying an elementary matrix. They are row switching, row multiplication, and row addition. By applying these operations to an identity matrix, I, the resultant matrix, T, is a transformation matrix, such that left multiplying T with a matrix A, i.e., T * A, is equivalent to applying the same sequence of operations to A. Similarly, the three elementary column operations are: column switching, column multiplication, and column addition. Column operations correspond to right multiplying a transformation matrix.
    See Also:
    Wikipedia: Elementary matrix
    • Constructor Detail

      • ElementaryOperation

        public ElementaryOperation​(int dim)
        Construct a transformation matrix of elementary operations. The initial transformation matrix T is an identity matrix.
        Parameters:
        dim - the dimension of T
      • ElementaryOperation

        public ElementaryOperation​(int nRows,
                                   int nCols)
        Construct a transformation matrix of elementary operations. The initial transformation matrix T is an identity matrix, if it is square. Otherwise, the rightmost columns are padded with zeros.
        Parameters:
        nRows - the number of rows of T
        nCols - the number of columns of T
      • ElementaryOperation

        public ElementaryOperation​(Matrix A)
        Transform A by elementary operations.
        Parameters:
        A - a matrix
    • Method Detail

      • nRows

        public int nRows()
        Description copied from interface: Table
        Gets the number of rows. Rows count from 1.
        Specified by:
        nRows in interface Table
        Returns:
        the number of rows
      • nCols

        public int nCols()
        Description copied from interface: Table
        Gets the number of columns. Columns count from 1.
        Specified by:
        nCols in interface Table
        Returns:
        the number of columns
      • get

        public double get​(int i,
                          int j)
        Description copied from interface: MatrixAccess
        Get the matrix entry at [i,j].
        Specified by:
        get in interface MatrixAccess
        Parameters:
        i - the row index
        j - the column index
        Returns:
        A[i,j]
      • T

        public Matrix T()
        Get the transformed matrix T.
        Returns:
        T
      • swapRow

        public ElementaryOperation swapRow​(int i1,
                                           int i2)
        Swap rows:
        
         A[i1, ] = A[i2, ]
         A[i2, ] = A[i1, ]
         
        Parameters:
        i1 - becoming row i2
        i2 - becoming row i1
        Returns:
        the modified self
      • scaleRow

        public ElementaryOperation scaleRow​(int i,
                                            double c)
        Scale a row:
        A[i, ] = c * A[i, ]
        Parameters:
        i - the row to be scaled
        c - the scaling factor
        Returns:
        the modified self
      • addRow

        public ElementaryOperation addRow​(int i1,
                                          int i2,
                                          double c)
        Row addition:
        A[i1, ] = A[i1, ] + c * A[i2, ]
        Parameters:
        i1 - addend; the row to add to; the row is modified afterward
        i2 - the row to add with
        c - the scaling factor for row i2
        Returns:
        the modified self
      • swapColumn

        public ElementaryOperation swapColumn​(int j1,
                                              int j2)
        Swap columns:
        
         A[, j1] = A[, j2]
         A[, j2] = A[, j1]
         
        Parameters:
        j1 - becoming column j2
        j2 - becoming column j1
        Returns:
        the modified self
      • scaleColumn

        public ElementaryOperation scaleColumn​(int j,
                                               double c)
        Scale a column:
        A[, j] = c * A[, j]
        Parameters:
        j - the column to be scaled
        c - the scaling factor
        Returns:
        the modified self
      • addColumn

        public ElementaryOperation addColumn​(int j1,
                                             int j2,
                                             double c)
        Column addition:
        A[, j1] = A[, j1] + c * A[, j2]
        Parameters:
        j1 - addend; the column to add to; the column is modified afterward
        j2 - the column to add with
        c - the scaling factor for col2
        Returns:
        the modified self
      • set

        @Deprecated
        public void set​(int i,
                        int j,
                        double value)
                 throws MatrixAccessException
        Deprecated.
        Description copied from interface: MatrixAccess
        Set the matrix entry at [i,j] to a value. This is the only method that may change a matrix.
        Specified by:
        set in interface MatrixAccess
        Parameters:
        i - the row index
        j - the column index
        value - the value to set A[i,j] to
        Throws:
        MatrixAccessException - if i or j is out of range