Class CommonsMatrixAlgebra

    • Constructor Detail

      • CommonsMatrixAlgebra

        public CommonsMatrixAlgebra()
    • Method Detail

      • getCondition

        public double getCondition​(Matrix m)
        Description copied from class: MatrixAlgebra
        Returns the condition number of the matrix.
        Specified by:
        getCondition in class MatrixAlgebra
        Parameters:
        m - A matrix, not null
        Returns:
        The condition number of the matrix
      • getDeterminant

        public double getDeterminant​(Matrix m)
        Description copied from class: MatrixAlgebra
        Returns the determinant of the matrix.
        Specified by:
        getDeterminant in class MatrixAlgebra
        Parameters:
        m - A matrix, not null
        Returns:
        The determinant of the matrix
      • getInnerProduct

        public double getInnerProduct​(Matrix m1,
                                      Matrix m2)
        Description copied from class: MatrixAlgebra
        Returns the inner (or dot) product.
        Specified by:
        getInnerProduct in class MatrixAlgebra
        Parameters:
        m1 - A vector, not null
        m2 - A vector, not null
        Returns:
        The scalar dot product
      • getInverse

        public DoubleMatrix getInverse​(Matrix m)
        Description copied from class: MatrixAlgebra
        Returns the inverse (or pseudo-inverse) of the matrix.
        Specified by:
        getInverse in class MatrixAlgebra
        Parameters:
        m - A matrix, not null
        Returns:
        The inverse matrix
      • getNorm2

        public double getNorm2​(Matrix m)
        Description copied from class: MatrixAlgebra
        For a vector, returns $L_2$ norm (also known as the Euclidean norm).

        For a matrix, returns the spectral norm

        Specified by:
        getNorm2 in class MatrixAlgebra
        Parameters:
        m - A vector or matrix, not null
        Returns:
        the norm
      • getPower

        public DoubleMatrix getPower​(Matrix m,
                                     int p)
        Description copied from class: MatrixAlgebra
        Returns a matrix raised to an integer power, e.g. $\mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}$.
        Specified by:
        getPower in class MatrixAlgebra
        Parameters:
        m - A square matrix, not null
        p - An integer power
        Returns:
        The result
      • getPower

        public DoubleMatrix getPower​(Matrix m,
                                     double p)
        Returns a real matrix raised to some real power Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices.
        Specified by:
        getPower in class MatrixAlgebra
        Parameters:
        m - The symmetric matrix to take the power of.
        p - The power to raise to matrix to
        Returns:
        The result
      • getTrace

        public double getTrace​(Matrix m)
        Description copied from class: MatrixAlgebra
        Returns the trace (i.e. sum of diagonal elements) of a matrix.
        Specified by:
        getTrace in class MatrixAlgebra
        Parameters:
        m - A matrix, not null. The matrix must be square.
        Returns:
        The trace
      • multiply

        public Matrix multiply​(Matrix m1,
                               Matrix m2)
        Multiplies two matrices. The following combinations of input matrices m1 and m2 are allowed:
        • m1 = 2-D matrix, m2 = 2-D matrix, returns $\mathbf{C} = \mathbf{AB}$
        • m1 = 2-D matrix, m2 = 1-D matrix, returns $\mathbf{C} = \mathbf{A}b$
        Specified by:
        multiply in class MatrixAlgebra
        Parameters:
        m1 - The first matrix, not null.
        m2 - The second matrix, not null.
        Returns:
        The product of the two matrices.