Class RealMatrix

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Double>, Matrix<java.lang.Double>

    public class RealMatrix
    extends java.lang.Object
    implements Matrix<java.lang.Double>
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      RealMatrix add​(java.lang.Double rhs)
      Add the given value to each element in this matrix, returning the result.
      RealMatrix add​(Matrix<java.lang.Double> rhs)
      Adds the given matrix to this one.
      void addToElement​(int row, int col, java.lang.Double value)
      Replace the value of an element with itself plus a given value.
      RealMatrix appendCols​(Matrix<java.lang.Double> cols)
      Creates a new matrix consisting of the given columns appended to the right of this matrix.
      RealMatrix appendRows​(Matrix<java.lang.Double> rows)
      Creates a new matrix consisting of the given rows appended to the bottom of this matrix.
      static RealMatrix asColumn​(double... values)  
      static RealMatrix asColumn​(java.lang.Double[] values)  
      static RealMatrix asRealMatrix​(Matrix<java.lang.Double> matrix)  
      static RealMatrix asRow​(double... values)  
      static RealMatrix asRow​(java.lang.Double[] values)  
      int cols()
      Returns the number of columns in the matrix.
      RealMatrix copy()
      Returns a deep copy of the matrix.
      RealMatrix div​(java.lang.Double rhs)
      Divides all elements in this matrix by the given value.
      RealMatrix div​(Matrix<java.lang.Double> rhs)
      Multiplies this matrix by the inverse of another.
      RealMatrix divide​(java.lang.Double rhs)
      Divides all elements in this matrix by the given value.
      RealMatrix divide​(Matrix<java.lang.Double> rhs)
      Multiplies this matrix by the inverse of another.
      void divideElement​(int row, int col, java.lang.Double value)
      Replace the value of an element with itself divided by a given value.
      RealMatrix elementDivide​(Matrix<java.lang.Double> rhs)
      Performs element-wise division of this matrix by the specified matrix (divides each element in this matrix by its corresponding element in the other).
      RealMatrix elementMultiply​(Matrix<java.lang.Double> rhs)
      Computes the element-wise product of this matrix with another (this .* other).
      java.lang.Double get​(int row, int col)
      Returns the element at the given indices.
      double[] getCol​(int col)  
      java.lang.Double[] getColArray​(int col)
      Returns the values in a single column as an array.
      RealMatrix getColMatrix​(int col)
      Returns a single column as a column matrix.
      RealMatrix getColQuadratures()  
      RealMatrix getColSums()
      Returns a row matrix of the sums of each column in this matrix.
      java.lang.Double[][] getData()
      Returns all elements as a 2-dimensional array.
      java.lang.Double getDeterminant()
      Returns the determinant of the matrix (only for square matrices).
      RealMatrix getDiagonal()
      Returns the diagonal values of the square matrix as a column matrix.
      java.lang.Double[] getFlatData()
      Returns all elements in a 1-dimensional array.
      LU<java.lang.Double> getLU()
      Computes and returns the LU decomposition of this matrix (only for square matrices).
      double getMaxElement()  
      double getMinElement()  
      double getNorm()  
      RealMatrix.QR getQR()
      Computes and returns the QR decomposition of this matrix.
      double[] getRow​(int row)  
      java.lang.Double[] getRowArray​(int row)
      Returns the values in a single row as an array.
      RealMatrix getRowMatrix​(int row)
      Returns a single row as a row matrix.
      RealMatrix getRowQuadratures()  
      RealMatrix getRowSums()
      Returns a column matrix of the sums of each row in this matrix.
      RealMatrix getSubMatrix​(int[] rows, int[] cols)
      Returns a sub-matrix containing only the specified rows and columns from this matrix.
      RealMatrix getSubMatrix​(int startRow, int endRow, int startCol, int endCol)
      Returns a sub-matrix containing only the rows and columns specified in the given ranges (inclusive).
      java.lang.Double getTrace()
      Returns the trace of the matrix (sum of diagonal elements).
      static RealMatrix identity​(int size)  
      RealMatrix invert()
      Inverts the matrix and returns the result (only for square matrices).
      boolean isSingular()
      Returns whether the matrix is singular (has no inverse).
      static RealMatrix iterableToCol​(java.lang.Iterable<java.lang.Double> iterable)  
      RealMatrix leftDivide​(java.lang.Double lhs)
      Divides the given value by each element in the matrix returning a matrix of the results.
      RealMatrix leftDivide​(Matrix<java.lang.Double> rhs)
      Multiplies the supplied matrix by the inverse of this matrix.
      RealMatrix leftElementDivide​(Matrix<java.lang.Double> lhs)
      Performs element-wise division of the specified matrix by this matrix (divides each element in the supplied matrix by its corresponding element in this matrix).
      RealMatrix leftElementMultiply​(Matrix<java.lang.Double> lhs)
      Computes the element-wise product of another matrix with this matrix (other * this).
      RealMatrix leftMultiply​(java.lang.Double lhs)
      Pre-multiplies each element in this matrix by a scalar value.
      RealMatrix leftMultiply​(Matrix<java.lang.Double> lhs)
      Multiplies another matrix by this matrix (other * this).
      RealMatrix map​(GFunction<java.lang.Double,​java.lang.Double> mapper)
      Map all elements of this matrix into a new matrix according to the provided mapping function.
      RealMatrix map​(Matrix.EntryMapper<java.lang.Double,​java.lang.Double> mapper)
      Map all elements of this matrix into a new matrix according to the provided mapping function.
      void mapCol​(int col, Matrix.LinearMapper<java.lang.Double> mapper)
      Maps the values of a specified column onto themselves.
      void mapColToCol​(int source, int dest, Matrix.LinearMapper<java.lang.Double> mapper)
      Maps one column onto another.
      void mapElement​(int row, int col, GFunction<java.lang.Double,​java.lang.Double> mapper)
      Replace an element with the value of a function of itself.
      void mapRow​(int row, Matrix.LinearMapper<java.lang.Double> mapper)
      Maps the values of a specified row onto themselves.
      void mapRowToRow​(int source, int dest, Matrix.LinearMapper<java.lang.Double> mapper)
      Maps one row onto another.
      RealMatrix minus​(java.lang.Double rhs)
      Subtracts the given value from each element in this matrix, returning the result.
      RealMatrix minus​(Matrix<java.lang.Double> rhs)
      Subtracts the given matrix from this one, returning the result.
      RealMatrix multiply​(java.lang.Double rhs)
      Multiplies each element in this matrix by a scalar value.
      RealMatrix multiply​(Matrix<java.lang.Double> rhs)
      Multiplies this matrix by another (this * other).
      RealMatrix multiply​(org.apache.commons.math.linear.RealMatrix rhs)  
      void multiplyElement​(int row, int col, java.lang.Double value)
      Replace the value of an element with itself multiplied by a given value.
      RealMatrix plus​(java.lang.Double rhs)
      Add the given value to each element in this matrix, returning the result.
      RealMatrix plus​(Matrix<java.lang.Double> rhs)
      Adds the given matrix to this one.
      org.apache.commons.math.linear.RealMatrix realMatrix()  
      RealMatrix reshape​(int rows, int cols)
      Reshapes the elements in the matrix into a matrix of different dimensions (but same total number of elements), returning the result.
      RealMatrix rotate2D​(double angle)  
      static RealMatrix rotation2D​(double angle)  
      int rows()
      Returns the number of rows in the matrix.
      void set​(int row, int col, java.lang.Double value)
      Sets the matrix element at the given (row, col) position.
      void setAll​(double[] values)  
      void setAll​(java.lang.Double value)
      Sets all elements to a single value.
      void setAll​(java.lang.Double... values)
      Sets all elements in the matrix.
      void setCol​(int col, double... values)  
      void setDiagonal​(java.lang.Double value)
      Sets the values along the leading diagonal to the same value.
      void setDiagonal​(java.lang.Double... values)
      Sets the elements on the leading diagonal of the matrix.
      void setRow​(int row, double... values)  
      RealMatrix subtract​(java.lang.Double rhs)
      Subtracts the given value from each element in this matrix, returning the result.
      RealMatrix subtract​(Matrix<java.lang.Double> rhs)
      Subtracts the given matrix from this one, returning the result.
      void subtractFromElement​(int row, int col, java.lang.Double value)
      Replace the value of an element with itself minus a given value.
      RealMatrix times​(java.lang.Double rhs)
      Multiplies each element in this matrix by a scalar value.
      RealMatrix times​(Matrix<java.lang.Double> rhs)
      Multiplies this matrix by another (this * other).
      java.lang.String toString()
      Returns a textual representation of this matrix.
      RealMatrix transpose()
      Transposes the matrix and returns the result.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        spliterator
    • Constructor Detail

      • RealMatrix

        public RealMatrix​(int rows,
                          int cols)
      • RealMatrix

        public RealMatrix​(java.lang.String text)
      • RealMatrix

        public RealMatrix​(int rows,
                          int cols,
                          java.lang.Double[] values)
      • RealMatrix

        public RealMatrix​(int rows,
                          int cols,
                          double... values)
      • RealMatrix

        public RealMatrix​(double[][] data)
      • RealMatrix

        public RealMatrix​(org.apache.commons.math.linear.RealMatrix matrix)
      • RealMatrix

        public RealMatrix​(Matrix<java.lang.Double> matrix)
    • Method Detail

      • asRealMatrix

        public static RealMatrix asRealMatrix​(Matrix<java.lang.Double> matrix)
      • asRow

        public static RealMatrix asRow​(java.lang.Double[] values)
      • asRow

        public static RealMatrix asRow​(double... values)
      • asColumn

        public static RealMatrix asColumn​(double... values)
      • asColumn

        public static RealMatrix asColumn​(java.lang.Double[] values)
      • identity

        public static RealMatrix identity​(int size)
      • rotation2D

        public static RealMatrix rotation2D​(double angle)
      • iterableToCol

        public static RealMatrix iterableToCol​(java.lang.Iterable<java.lang.Double> iterable)
      • realMatrix

        public org.apache.commons.math.linear.RealMatrix realMatrix()
      • rows

        public int rows()
        Description copied from interface: Matrix
        Returns the number of rows in the matrix.
        Specified by:
        rows in interface Matrix<java.lang.Double>
        Returns:
        Number of rows
      • cols

        public int cols()
        Description copied from interface: Matrix
        Returns the number of columns in the matrix.
        Specified by:
        cols in interface Matrix<java.lang.Double>
        Returns:
        Number of columns
      • get

        public java.lang.Double get​(int row,
                                    int col)
        Description copied from interface: Matrix
        Returns the element at the given indices.
        Specified by:
        get in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        col - Column index
        Returns:
        Element at (row,col)
      • getData

        public java.lang.Double[][] getData()
        Description copied from interface: Matrix
        Returns all elements as a 2-dimensional array.
        Specified by:
        getData in interface Matrix<java.lang.Double>
        Returns:
        All elements
      • divide

        public RealMatrix divide​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Multiplies this matrix by the inverse of another.
        Specified by:
        divide in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to "divide" by (left-hand side)
        Returns:
        Result of "division"
      • times

        public RealMatrix times​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Multiplies this matrix by another (this * other).
        Specified by:
        times in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to multiply by (right-hand side)
        Returns:
        Result of multiplication
      • times

        public RealMatrix times​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Multiplies each element in this matrix by a scalar value. (Kotlin operator overload)
        Specified by:
        times in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Scalar value.
        Returns:
        Result of multiplication
      • div

        public RealMatrix div​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Multiplies this matrix by the inverse of another.
        Specified by:
        div in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to "divide" by (left-hand side)
        Returns:
        Result of "division"
      • div

        public RealMatrix div​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Divides all elements in this matrix by the given value.
        Specified by:
        div in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Value to divide by
        Returns:
        Result of division
      • rotate2D

        public RealMatrix rotate2D​(double angle)
      • plus

        public RealMatrix plus​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Adds the given matrix to this one. (Adds each element with its corresponding element).
        Specified by:
        plus in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to add
        Returns:
        Result of addition
      • plus

        public RealMatrix plus​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Add the given value to each element in this matrix, returning the result.
        Specified by:
        plus in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Value to add
        Returns:
        Result of addition
      • minus

        public RealMatrix minus​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Subtracts the given matrix from this one, returning the result.
        Specified by:
        minus in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to subtract
        Returns:
        Result of subtraction
      • minus

        public RealMatrix minus​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Subtracts the given value from each element in this matrix, returning the result.
        Specified by:
        minus in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Value to subtract
        Returns:
        Result of subtraction
      • getFlatData

        public java.lang.Double[] getFlatData()
        Description copied from interface: Matrix
        Returns all elements in a 1-dimensional array.
        Specified by:
        getFlatData in interface Matrix<java.lang.Double>
        Returns:
        All elements
      • getDiagonal

        public RealMatrix getDiagonal()
        Description copied from interface: Matrix
        Returns the diagonal values of the square matrix as a column matrix.
        Specified by:
        getDiagonal in interface Matrix<java.lang.Double>
        Returns:
        Diagonal values
      • setDiagonal

        public void setDiagonal​(java.lang.Double... values)
        Description copied from interface: Matrix
        Sets the elements on the leading diagonal of the matrix. Matrix must be square.
        Specified by:
        setDiagonal in interface Matrix<java.lang.Double>
        Parameters:
        values - Diagonal elements
      • setDiagonal

        public void setDiagonal​(java.lang.Double value)
        Description copied from interface: Matrix
        Sets the values along the leading diagonal to the same value. Matrix must be square.
        Specified by:
        setDiagonal in interface Matrix<java.lang.Double>
        Parameters:
        value - Element value
      • setRow

        public void setRow​(int row,
                           double... values)
      • setCol

        public void setCol​(int col,
                           double... values)
      • getRow

        public double[] getRow​(int row)
      • getCol

        public double[] getCol​(int col)
      • getNorm

        public double getNorm()
      • getMaxElement

        public double getMaxElement()
      • getMinElement

        public double getMinElement()
      • set

        public void set​(int row,
                        int col,
                        java.lang.Double value)
        Description copied from interface: Matrix
        Sets the matrix element at the given (row, col) position.
        Specified by:
        set in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        col - Column index
        value - Element value to set
      • setAll

        public void setAll​(java.lang.Double value)
        Description copied from interface: Matrix
        Sets all elements to a single value.
        Specified by:
        setAll in interface Matrix<java.lang.Double>
        Parameters:
        value - Value to set
      • setAll

        public void setAll​(java.lang.Double... values)
        Description copied from interface: Matrix
        Sets all elements in the matrix.
        Specified by:
        setAll in interface Matrix<java.lang.Double>
        Parameters:
        values - Elements
      • setAll

        public void setAll​(double[] values)
      • toString

        public java.lang.String toString()
        Description copied from interface: Matrix
        Returns a textual representation of this matrix.
        Specified by:
        toString in interface Matrix<java.lang.Double>
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation
      • mapElement

        public void mapElement​(int row,
                               int col,
                               GFunction<java.lang.Double,​java.lang.Double> mapper)
        Description copied from interface: Matrix
        Replace an element with the value of a function of itself.
        Specified by:
        mapElement in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        col - Column index
        mapper - Function for mapping
      • multiplyElement

        public void multiplyElement​(int row,
                                    int col,
                                    java.lang.Double value)
        Description copied from interface: Matrix
        Replace the value of an element with itself multiplied by a given value.
        Specified by:
        multiplyElement in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        col - Column index
        value - Factor to multiply by
      • divideElement

        public void divideElement​(int row,
                                  int col,
                                  java.lang.Double value)
        Description copied from interface: Matrix
        Replace the value of an element with itself divided by a given value.
        Specified by:
        divideElement in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        col - Column index
        value - Factor to divide by
      • addToElement

        public void addToElement​(int row,
                                 int col,
                                 java.lang.Double value)
        Description copied from interface: Matrix
        Replace the value of an element with itself plus a given value.
        Specified by:
        addToElement in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        col - Column index
        value - Value to add
      • subtractFromElement

        public void subtractFromElement​(int row,
                                        int col,
                                        java.lang.Double value)
        Description copied from interface: Matrix
        Replace the value of an element with itself minus a given value.
        Specified by:
        subtractFromElement in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        col - Column index
        value - Value to subtract
      • mapRow

        public void mapRow​(int row,
                           Matrix.LinearMapper<java.lang.Double> mapper)
        Description copied from interface: Matrix
        Maps the values of a specified row onto themselves.
        Specified by:
        mapRow in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index to map
        mapper - Function the defines mapping
      • mapCol

        public void mapCol​(int col,
                           Matrix.LinearMapper<java.lang.Double> mapper)
        Description copied from interface: Matrix
        Maps the values of a specified column onto themselves.
        Specified by:
        mapCol in interface Matrix<java.lang.Double>
        Parameters:
        col - Column index to map
        mapper - Function the defines mapping
      • mapRowToRow

        public void mapRowToRow​(int source,
                                int dest,
                                Matrix.LinearMapper<java.lang.Double> mapper)
        Description copied from interface: Matrix
        Maps one row onto another.
        Specified by:
        mapRowToRow in interface Matrix<java.lang.Double>
        Parameters:
        source - Source row index
        dest - Destination row index
        mapper - Function that defines mapping
      • mapColToCol

        public void mapColToCol​(int source,
                                int dest,
                                Matrix.LinearMapper<java.lang.Double> mapper)
        Description copied from interface: Matrix
        Maps one column onto another.
        Specified by:
        mapColToCol in interface Matrix<java.lang.Double>
        Parameters:
        source - Source column index
        dest - Destination column index
        mapper - Function that defines mapping
      • getRowArray

        public java.lang.Double[] getRowArray​(int row)
        Description copied from interface: Matrix
        Returns the values in a single row as an array.
        Specified by:
        getRowArray in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        Returns:
        Array of values
      • getColArray

        public java.lang.Double[] getColArray​(int col)
        Description copied from interface: Matrix
        Returns the values in a single column as an array.
        Specified by:
        getColArray in interface Matrix<java.lang.Double>
        Parameters:
        col - Column index
        Returns:
        Array of values
      • getRowMatrix

        public RealMatrix getRowMatrix​(int row)
        Description copied from interface: Matrix
        Returns a single row as a row matrix.
        Specified by:
        getRowMatrix in interface Matrix<java.lang.Double>
        Parameters:
        row - Row index
        Returns:
        Row matrix
      • getColMatrix

        public RealMatrix getColMatrix​(int col)
        Description copied from interface: Matrix
        Returns a single column as a column matrix.
        Specified by:
        getColMatrix in interface Matrix<java.lang.Double>
        Parameters:
        col - Column index
        Returns:
        Column matrix
      • multiply

        public RealMatrix multiply​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Multiplies this matrix by another (this * other).
        Specified by:
        multiply in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Right-hand side of multiplication
        Returns:
        Result of multiplication
      • multiply

        public RealMatrix multiply​(org.apache.commons.math.linear.RealMatrix rhs)
      • leftMultiply

        public RealMatrix leftMultiply​(Matrix<java.lang.Double> lhs)
        Description copied from interface: Matrix
        Multiplies another matrix by this matrix (other * this).
        Specified by:
        leftMultiply in interface Matrix<java.lang.Double>
        Parameters:
        lhs - Matrix to multiply (left-hand side)
        Returns:
        Result of multiplication
      • multiply

        public RealMatrix multiply​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Multiplies each element in this matrix by a scalar value.
        Specified by:
        multiply in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Scalar value.
        Returns:
        Result of multiplication
      • leftMultiply

        public RealMatrix leftMultiply​(java.lang.Double lhs)
        Description copied from interface: Matrix
        Pre-multiplies each element in this matrix by a scalar value.
        Specified by:
        leftMultiply in interface Matrix<java.lang.Double>
        Parameters:
        lhs - Scalar value.
        Returns:
        Result of multiplication
      • elementMultiply

        public RealMatrix elementMultiply​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Computes the element-wise product of this matrix with another (this .* other).
        Specified by:
        elementMultiply in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to multiply by (right-hand side)
        Returns:
        Result of multiplication
      • leftElementMultiply

        public RealMatrix leftElementMultiply​(Matrix<java.lang.Double> lhs)
        Description copied from interface: Matrix
        Computes the element-wise product of another matrix with this matrix (other * this).
        Specified by:
        leftElementMultiply in interface Matrix<java.lang.Double>
        Parameters:
        lhs - Matrix to multiply (left-hand side)
        Returns:
        Result of multiplication
      • elementDivide

        public RealMatrix elementDivide​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Performs element-wise division of this matrix by the specified matrix (divides each element in this matrix by its corresponding element in the other).
        Specified by:
        elementDivide in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to divide by
        Returns:
        Result of division
      • leftElementDivide

        public RealMatrix leftElementDivide​(Matrix<java.lang.Double> lhs)
        Description copied from interface: Matrix
        Performs element-wise division of the specified matrix by this matrix (divides each element in the supplied matrix by its corresponding element in this matrix).
        Specified by:
        leftElementDivide in interface Matrix<java.lang.Double>
        Parameters:
        lhs - Matrix to divide
        Returns:
        Result of division
      • divide

        public RealMatrix divide​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Divides all elements in this matrix by the given value.
        Specified by:
        divide in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Value to divide by
        Returns:
        Result of division
      • leftDivide

        public RealMatrix leftDivide​(java.lang.Double lhs)
        Description copied from interface: Matrix
        Divides the given value by each element in the matrix returning a matrix of the results.
        Specified by:
        leftDivide in interface Matrix<java.lang.Double>
        Parameters:
        lhs - Value to be divided
        Returns:
        Result of division
      • add

        public RealMatrix add​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Adds the given matrix to this one. (Adds each element with its corresponding element).
        Specified by:
        add in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to add
        Returns:
        Result of addition
      • add

        public RealMatrix add​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Add the given value to each element in this matrix, returning the result.
        Specified by:
        add in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Value to add
        Returns:
        Result of addition
      • subtract

        public RealMatrix subtract​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Subtracts the given matrix from this one, returning the result.
        Specified by:
        subtract in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to subtract
        Returns:
        Result of subtraction
      • subtract

        public RealMatrix subtract​(java.lang.Double rhs)
        Description copied from interface: Matrix
        Subtracts the given value from each element in this matrix, returning the result.
        Specified by:
        subtract in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Value to subtract
        Returns:
        Result of subtraction
      • map

        public RealMatrix map​(Matrix.EntryMapper<java.lang.Double,​java.lang.Double> mapper)
        Description copied from interface: Matrix
        Map all elements of this matrix into a new matrix according to the provided mapping function.
        Specified by:
        map in interface Matrix<java.lang.Double>
        Parameters:
        mapper - Mapping function
        Returns:
        Mapped matrix
      • map

        public RealMatrix map​(GFunction<java.lang.Double,​java.lang.Double> mapper)
        Description copied from interface: Matrix
        Map all elements of this matrix into a new matrix according to the provided mapping function.
        Specified by:
        map in interface Matrix<java.lang.Double>
        Parameters:
        mapper - Mapping function
        Returns:
        Mapped matrix
      • copy

        public RealMatrix copy()
        Description copied from interface: Matrix
        Returns a deep copy of the matrix.
        Specified by:
        copy in interface Matrix<java.lang.Double>
        Returns:
        Copy of matrix
      • getSubMatrix

        public RealMatrix getSubMatrix​(int[] rows,
                                       int[] cols)
        Description copied from interface: Matrix
        Returns a sub-matrix containing only the specified rows and columns from this matrix.
        Specified by:
        getSubMatrix in interface Matrix<java.lang.Double>
        Parameters:
        rows - Array of row indices
        cols - Array of column indices
        Returns:
        Sub-matrix
      • getSubMatrix

        public RealMatrix getSubMatrix​(int startRow,
                                       int endRow,
                                       int startCol,
                                       int endCol)
        Description copied from interface: Matrix
        Returns a sub-matrix containing only the rows and columns specified in the given ranges (inclusive).
        Specified by:
        getSubMatrix in interface Matrix<java.lang.Double>
        Parameters:
        startRow - Start of row range
        endRow - End of row range
        startCol - Start of column range
        endCol - End of column range
        Returns:
        Sub-matrix
      • appendRows

        public RealMatrix appendRows​(Matrix<java.lang.Double> rows)
        Description copied from interface: Matrix
        Creates a new matrix consisting of the given rows appended to the bottom of this matrix.
        Specified by:
        appendRows in interface Matrix<java.lang.Double>
        Parameters:
        rows - Rows to append (must match column dimension)
        Returns:
        Combined matrix
      • appendCols

        public RealMatrix appendCols​(Matrix<java.lang.Double> cols)
        Description copied from interface: Matrix
        Creates a new matrix consisting of the given columns appended to the right of this matrix.
        Specified by:
        appendCols in interface Matrix<java.lang.Double>
        Parameters:
        cols - Columns to append (must match row dimension)
        Returns:
        Combined matrix
      • isSingular

        public boolean isSingular()
        Description copied from interface: Matrix
        Returns whether the matrix is singular (has no inverse).
        Specified by:
        isSingular in interface Matrix<java.lang.Double>
        Returns:
        Singular?
      • getDeterminant

        public java.lang.Double getDeterminant()
        Description copied from interface: Matrix
        Returns the determinant of the matrix (only for square matrices).
        Specified by:
        getDeterminant in interface Matrix<java.lang.Double>
        Returns:
        Determinant value
      • getTrace

        public java.lang.Double getTrace()
        Description copied from interface: Matrix
        Returns the trace of the matrix (sum of diagonal elements).
        Specified by:
        getTrace in interface Matrix<java.lang.Double>
        Returns:
        Trace value
      • invert

        public RealMatrix invert()
        Description copied from interface: Matrix
        Inverts the matrix and returns the result (only for square matrices).
        Specified by:
        invert in interface Matrix<java.lang.Double>
        Returns:
        Inverted matrix
      • transpose

        public RealMatrix transpose()
        Description copied from interface: Matrix
        Transposes the matrix and returns the result.
        Specified by:
        transpose in interface Matrix<java.lang.Double>
        Returns:
        Transposed matrix
      • reshape

        public RealMatrix reshape​(int rows,
                                  int cols)
        Description copied from interface: Matrix
        Reshapes the elements in the matrix into a matrix of different dimensions (but same total number of elements), returning the result.

        rows * cols must equal this.size().

        Specified by:
        reshape in interface Matrix<java.lang.Double>
        Parameters:
        rows - New number of rows
        cols - New number of columns
        Returns:
        Reshaped matrix
      • leftDivide

        public RealMatrix leftDivide​(Matrix<java.lang.Double> rhs)
        Description copied from interface: Matrix
        Multiplies the supplied matrix by the inverse of this matrix.
        Specified by:
        leftDivide in interface Matrix<java.lang.Double>
        Parameters:
        rhs - Matrix to be "divided"
        Returns:
        Result of division
      • getQR

        public RealMatrix.QR getQR()
        Description copied from interface: Matrix
        Computes and returns the QR decomposition of this matrix.
        Specified by:
        getQR in interface Matrix<java.lang.Double>
        Returns:
        QR Decomposition
      • getLU

        public LU<java.lang.Double> getLU()
        Description copied from interface: Matrix
        Computes and returns the LU decomposition of this matrix (only for square matrices).
        Specified by:
        getLU in interface Matrix<java.lang.Double>
        Returns:
        LU Decomposition
      • getRowSums

        public RealMatrix getRowSums()
        Description copied from interface: Matrix
        Returns a column matrix of the sums of each row in this matrix.
        Specified by:
        getRowSums in interface Matrix<java.lang.Double>
        Returns:
        Column matrix of sums
      • getColSums

        public RealMatrix getColSums()
        Description copied from interface: Matrix
        Returns a row matrix of the sums of each column in this matrix.
        Specified by:
        getColSums in interface Matrix<java.lang.Double>
        Returns:
        Row matrix of sums
      • getRowQuadratures

        public RealMatrix getRowQuadratures()
      • getColQuadratures

        public RealMatrix getColQuadratures()