Package ptolemy.math

Class DoubleMatrixMath


  • public class DoubleMatrixMath
    extends java.lang.Object
    This class provides a library for mathematical operations on matrices of doubles. All calls expect matrix arguments to be non-null. In addition, all rows of the matrix are expected to have the same number of columns.

    Some algorithms are from:

    [1] Embree, Paul M. and Bruce Kimble. "C Language Algorithms for Digital Signal Processing," Prentice Hall, Englewood Cliffs, NJ, 1991.

    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    Jeff Tsay
    Pt.AcceptedRating:
    Yellow (ctsay)
    Pt.ProposedRating:
    Yellow (ctsay)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void _checkSameDimension​(java.lang.String caller, double[][] matrix1, double[][] matrix2)
      Check that the two matrix arguments are of the same dimension.
      protected static int _checkSquare​(java.lang.String caller, double[][] matrix)
      Check that the argument matrix is a square matrix.
      protected static int _columns​(double[][] matrix)
      Return the number of columns of a matrix.
      protected static java.lang.String _dimensionString​(double[][] matrix)
      Return a string that describes the number of rows and columns.
      protected static java.lang.Object[] _orthogonalizeRows​(double[][] rowArrays)
      Given a set of row vectors rowArrays[0] ...
      protected static int _rows​(double[][] matrix)
      Return the number of rows of a matrix.
      static double[][] add​(double[][] matrix, double z)
      Return a new matrix that is constructed from the argument by adding the second argument to every element.
      static double[][] add​(double[][] matrix1, double[][] matrix2)
      Return a new matrix that is constructed from the argument by adding the second matrix to the first one.
      static double[][] allocCopy​(double[][] matrix)
      Return a new matrix that is a copy of the matrix argument.
      static double[][] applyBinaryOperation​(DoubleBinaryOperation op, double[][] matrix, double z)
      Return a new array that is formed by applying an instance of a DoubleBinaryOperation to each element in the input matrix, using the matrix elements as the left operands and z as the right operand in all cases (op.operate(matrix[i][j], z)).
      static double[][] applyBinaryOperation​(DoubleBinaryOperation op, double[][] matrix1, double[][] matrix2)
      Return a new array that is formed by applying an instance of a DoubleBinaryOperation to the two matrices, element by element, using the elements of the first matrix as the left operands and the elements of the second matrix as the right operands.
      static double[][] applyBinaryOperation​(DoubleBinaryOperation op, double z, double[][] matrix)
      Return a new array that is formed by applying an instance of a DoubleBinaryOperation to each element in the input matrix, using z as the left operand in all cases and the matrix elements as the right operands (op.operate(z, matrix[i][j])).
      static double[][] applyUnaryOperation​(DoubleUnaryOperation op, double[][] matrix)
      Return a new array that is formed by applying an instance of a DoubleUnaryOperation to each element in the input matrix (op.operate(matrix[i][j])).
      static double[][] crop​(double[][] matrix, int rowStart, int colStart, int rowSpan, int colSpan)
      Return a new matrix that is a sub-matrix of the input matrix argument.
      static double determinant​(double[][] matrix)
      Return the determinant of a square matrix.
      static double[][] diag​(double[] array)
      Return a new matrix that is constructed by placing the elements of the input array on the diagonal of the square matrix, starting from the top left corner down to the bottom right corner.
      static double[][] divide​(double[][] matrix, double z)
      Return a new matrix that is constructed from the argument by dividing the second argument to every element.
      static double[][] divideElements​(double[][] matrix1, double[][] matrix2)
      Return a new matrix that is constructed by element by element division of the two matrix arguments.
      static double[] fromMatrixToArray​(double[][] matrix)
      Return a new array that is filled with the contents of the matrix.
      static double[] fromMatrixToArray​(double[][] matrix, int maxRow, int maxCol)
      Return a new array that is filled with the contents of the matrix.
      static double[][] hilbert​(int dim)
      Return a new matrix, which is defined by Aij = 1/(i+j+1), the Hilbert matrix.
      static double[][] identity​(int dim)
      Return an new identity matrix with the specified dimension.
      static double[][] identityMatrixDouble​(int dim)
      Return an new identity matrix with the specified dimension.
      static double[][] inverse​(double[][] A)
      Return a new matrix that is constructed by inverting the input matrix.
      static void matrixCopy​(double[][] sourceMatrix, double[][] destinationMatrix)
      Replace the destinationMatrix argument elements with the values of the sourceMatrix argument.
      static void matrixCopy​(double[][] sourceMatrix, int sourceRowStart, int sourceColStart, double[][] destinationMatrix, int destinationRowStart, int destinationColumnStart, int rowSpan, int columnSpan)
      Replace the destinationMatrix argument's values, in the specified row and column range, with the sourceMatrix argument's values, starting from specified row and column of the second matrix.
      static double[][] modulo​(double[][] matrix, double z)
      Return a new matrix that is constructed from the argument after performing modulo operation by the second argument to every element.
      static double[][] multiply​(double[][] matrix, double scaleFactor)
      Return a new matrix that is constructed by multiplying the matrix by a scaleFactor.
      static double[] multiply​(double[][] matrix, double[] array)
      Return a new array that is constructed from the argument by pre-multiplying the array (treated as a row vector) by a matrix.
      static double[][] multiply​(double[][] matrix1, double[][] matrix2)
      Return a new matrix that is constructed from the argument by multiplying the first matrix by the second one.
      static double[] multiply​(double[] array, double[][] matrix)
      Return a new array that is constructed from the argument by post-multiplying the matrix by an array (treated as a row vector).
      static double[][] multiplyElements​(double[][] matrix1, double[][] matrix2)
      Return a new matrix that is constructed by element by element multiplication of the two matrix arguments.
      static double[][] negative​(double[][] matrix)
      Return a new matrix that is the additive inverse of the argument matrix.
      static double[][] orthogonalizeColumns​(double[][] matrix)
      Return a new matrix that is formed by orthogonalizing the columns of the input matrix (the column vectors are orthogonal).
      static double[][] orthogonalizeRows​(double[][] matrix)
      Return a new matrix that is formed by orthogonalizing the rows of the input matrix (the row vectors are orthogonal).
      static double[][] orthonormalizeColumns​(double[][] matrix)
      Return a new matrix that is formed by orthonormalizing the columns of the input matrix (the column vectors are orthogonal and have norm 1).
      static double[][] orthonormalizeRows​(double[][] matrix)
      Return a new matrix that is formed by orthonormalizing the rows of the input matrix (the row vectors are orthogonal and have norm 1).
      static double[][][] qr​(double[][] matrix)
      Return a pair of matrices that are the decomposition of the input matrix (which must have linearly independent column vectors), which is m x n, into the matrix product of Q, which is m x n with orthonormal column vectors, and R, which is an invertible n x n upper triangular matrix.
      static double[][] subtract​(double[][] matrix1, double[][] matrix2)
      Return a new matrix that is constructed from the argument by subtracting the second matrix from the first one.
      static double sum​(double[][] matrix)
      Return the sum of the elements of a matrix.
      static Complex[][] toComplexMatrix​(double[][] matrix)
      Return a new matrix that is formed by converting the doubles in the argument matrix to complex numbers.
      static float[][] toFloatMatrix​(double[][] matrix)
      Return a new matrix that is formed by converting the doubles in the argument matrix to floats.
      static int[][] toIntegerMatrix​(double[][] matrix)
      Return a new matrix that is formed by converting the doubles in the argument matrix to integers.
      static long[][] toLongMatrix​(double[][] matrix)
      Return a new matrix that is formed by converting the doubles in the argument matrix to longs.
      static double[][] toMatrixFromArray​(double[] array, int rows, int cols)
      Return a new matrix of doubles that is initialized from a 1-D array.
      static java.lang.String toString​(double[][] matrix)
      Return a new String representing the matrix, formatted as in Java array initializers.
      static java.lang.String toString​(double[][] matrix, java.lang.String elementDelimiter, java.lang.String matrixBegin, java.lang.String matrixEnd, java.lang.String vectorBegin, java.lang.String vectorDelimiter, java.lang.String vectorEnd)
      Return a new String representing the matrix, formatted as specified by the ArrayStringFormat argument.
      static double trace​(double[][] matrix)
      Return the trace of a square matrix, which is the sum of the diagonal entries A11 + A22 + ...
      static double[][] transpose​(double[][] matrix)
      Return a new matrix that is constructed by transposing the input matrix.
      static boolean within​(double[][] matrix1, double[][] matrix2, double distance)
      Return true if the elements of the two matrices differ by no more than the specified distance.
      static boolean within​(double[][] matrix1, double[][] matrix2, double[][] errorMatrix)
      Return true if the elements of the two matrices differ by no more than the specified distances.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • add

        public static final double[][] add​(double[][] matrix,
                                           double z)
        Return a new matrix that is constructed from the argument by adding the second argument to every element.
        Parameters:
        matrix - A matrix of doubles.
        z - The double number to add.
        Returns:
        A new matrix of doubles.
      • add

        public static final double[][] add​(double[][] matrix1,
                                           double[][] matrix2)
        Return a new matrix that is constructed from the argument by adding the second matrix to the first one. If the two matrices are not the same size, throw an IllegalArgumentException.
        Parameters:
        matrix1 - The first matrix of doubles.
        matrix2 - The second matrix of doubles.
        Returns:
        A new matrix of doubles.
      • allocCopy

        public static final double[][] allocCopy​(double[][] matrix)
        Return a new matrix that is a copy of the matrix argument.
        Parameters:
        matrix - A matrix of doubles.
        Returns:
        A new matrix of doubles.
      • applyBinaryOperation

        public static final double[][] applyBinaryOperation​(DoubleBinaryOperation op,
                                                            double z,
                                                            double[][] matrix)
        Return a new array that is formed by applying an instance of a DoubleBinaryOperation to each element in the input matrix, using z as the left operand in all cases and the matrix elements as the right operands (op.operate(z, matrix[i][j])).
      • applyBinaryOperation

        public static final double[][] applyBinaryOperation​(DoubleBinaryOperation op,
                                                            double[][] matrix,
                                                            double z)
        Return a new array that is formed by applying an instance of a DoubleBinaryOperation to each element in the input matrix, using the matrix elements as the left operands and z as the right operand in all cases (op.operate(matrix[i][j], z)).
      • applyBinaryOperation

        public static final double[][] applyBinaryOperation​(DoubleBinaryOperation op,
                                                            double[][] matrix1,
                                                            double[][] matrix2)
        Return a new array that is formed by applying an instance of a DoubleBinaryOperation to the two matrices, element by element, using the elements of the first matrix as the left operands and the elements of the second matrix as the right operands. (op.operate(matrix1[i][j], matrix2[i][j])). If the matrices are not the same size, throw an IllegalArgumentException.
      • applyUnaryOperation

        public static final double[][] applyUnaryOperation​(DoubleUnaryOperation op,
                                                           double[][] matrix)
        Return a new array that is formed by applying an instance of a DoubleUnaryOperation to each element in the input matrix (op.operate(matrix[i][j])).
      • crop

        public static final double[][] crop​(double[][] matrix,
                                            int rowStart,
                                            int colStart,
                                            int rowSpan,
                                            int colSpan)
        Return a new matrix that is a sub-matrix of the input matrix argument. The row and column from which to start and the number of rows and columns to span are specified.
        Parameters:
        matrix - A matrix of doubles.
        rowStart - An int specifying which row to start on.
        colStart - An int specifying which column to start on.
        rowSpan - An int specifying how many rows to copy.
        colSpan - An int specifying how many columns to copy.
      • determinant

        public static final double determinant​(double[][] matrix)
        Return the determinant of a square matrix. If the matrix is not square, throw an IllegalArgumentException. This algorithm uses LU decomposition, and is taken from [1]
      • diag

        public static final double[][] diag​(double[] array)
        Return a new matrix that is constructed by placing the elements of the input array on the diagonal of the square matrix, starting from the top left corner down to the bottom right corner. All other elements are zero. The size of of the matrix is n x n, where n is the length of the input array.
      • divide

        public static final double[][] divide​(double[][] matrix,
                                              double z)
        Return a new matrix that is constructed from the argument by dividing the second argument to every element.
        Parameters:
        matrix - A matrix of doubles.
        z - The double number to divide.
        Returns:
        A new matrix of doubles.
      • divideElements

        public static final double[][] divideElements​(double[][] matrix1,
                                                      double[][] matrix2)
        Return a new matrix that is constructed by element by element division of the two matrix arguments. Each element of the first matrix is divided by the corresponding element of the second matrix. If the two matrices are not the same size, throw an IllegalArgumentException.
      • fromMatrixToArray

        public static final double[] fromMatrixToArray​(double[][] matrix)
        Return a new array that is filled with the contents of the matrix. The doubles are stored row by row, i.e. using the notation (row, column), the entries of the array are in the following order for a (m, n) matrix : (0, 0), (0, 1), (0, 2), ... , (0, n-1), (1, 0), (1, 1), ..., (m-1)(n-1)
        Parameters:
        matrix - A matrix of doubles.
        Returns:
        A new array of doubles.
      • fromMatrixToArray

        public static final double[] fromMatrixToArray​(double[][] matrix,
                                                       int maxRow,
                                                       int maxCol)
        Return a new array that is filled with the contents of the matrix. The maximum numbers of rows and columns to copy are specified so that entries lying outside of this range can be ignored. The maximum rows to copy cannot exceed the number of rows in the matrix, and the maximum columns to copy cannot exceed the number of columns in the matrix. The doubles are stored row by row, i.e. using the notation (row, column), the entries of the array are in the following order for a matrix, limited to m rows and n columns : (0, 0), (0, 1), (0, 2), ... , (0, n-1), (1, 0), (1, 1), ..., (m-1)(n-1)
        Parameters:
        matrix - A matrix of doubles.
        Returns:
        A new array of doubles.
      • hilbert

        public static final double[][] hilbert​(int dim)
        Return a new matrix, which is defined by Aij = 1/(i+j+1), the Hilbert matrix. The matrix is square with one dimension specifier required. This matrix is useful because it always has an inverse.
      • identity

        public static final double[][] identity​(int dim)
        Return an new identity matrix with the specified dimension. The matrix is square, so only one dimension specifier is needed. Note that this method does the same thing as identityDouble(), but the latter is more useful in the expression language.
      • identityMatrixDouble

        public static final double[][] identityMatrixDouble​(int dim)
        Return an new identity matrix with the specified dimension. The matrix is square, so only one dimension specifier is needed.
      • inverse

        public static final double[][] inverse​(double[][] A)
        Return a new matrix that is constructed by inverting the input matrix. If the input matrix is singular, throw an exception. This method is from [1].
        Throws:
        java.lang.IllegalArgumentException - If the matrix is singular.
      • matrixCopy

        public static final void matrixCopy​(double[][] sourceMatrix,
                                            double[][] destinationMatrix)
        Replace the destinationMatrix argument elements with the values of the sourceMatrix argument. The destinationMatrix argument must be large enough to hold all the values of sourceMatrix argument.
        Parameters:
        destinationMatrix - A matrix of doubles, used as the destination.
        sourceMatrix - A matrix of doubles, used as the source.
      • matrixCopy

        public static final void matrixCopy​(double[][] sourceMatrix,
                                            int sourceRowStart,
                                            int sourceColStart,
                                            double[][] destinationMatrix,
                                            int destinationRowStart,
                                            int destinationColumnStart,
                                            int rowSpan,
                                            int columnSpan)
        Replace the destinationMatrix argument's values, in the specified row and column range, with the sourceMatrix argument's values, starting from specified row and column of the second matrix.
        Parameters:
        sourceMatrix - A matrix of doubles, used as the destination.
        sourceRowStart - An int specifying the starting row of the source.
        sourceColStart - An int specifying the starting column of the source.
        destinationMatrix - A matrix of doubles, used as the destination.
        destinationRowStart - An int specifying the starting row of the destination.
        destinationColumnStart - An int specifying the starting column of the destination.
        rowSpan - An int specifying how many rows to copy.
        columnSpan - An int specifying how many columns to copy.
      • modulo

        public static final double[][] modulo​(double[][] matrix,
                                              double z)
        Return a new matrix that is constructed from the argument after performing modulo operation by the second argument to every element.
        Parameters:
        matrix - A matrix of doubles.
        z - The double number to divide.
        Returns:
        A new matrix of doubles.
      • multiply

        public static final double[][] multiply​(double[][] matrix,
                                                double scaleFactor)
        Return a new matrix that is constructed by multiplying the matrix by a scaleFactor.
      • multiply

        public static final double[] multiply​(double[][] matrix,
                                              double[] array)
        Return a new array that is constructed from the argument by pre-multiplying the array (treated as a row vector) by a matrix. The number of rows of the matrix must equal the number of elements in the array. The returned array will have a length equal to the number of columns of the matrix.
      • multiply

        public static final double[] multiply​(double[] array,
                                              double[][] matrix)
        Return a new array that is constructed from the argument by post-multiplying the matrix by an array (treated as a row vector). The number of columns of the matrix must equal the number of elements in the array. The returned array will have a length equal to the number of rows of the matrix.
      • multiply

        public static final double[][] multiply​(double[][] matrix1,
                                                double[][] matrix2)
        Return a new matrix that is constructed from the argument by multiplying the first matrix by the second one. Note this operation is not commutative, so care must be taken in the ordering of the arguments. The number of columns of matrix1 must equal the number of rows of matrix2. If matrix1 is of size m x n, and matrix2 is of size n x p, the returned matrix will have size m x p.

        Note that this method is different from the other multiply() methods in that this method does not do pointwise multiplication.

        Parameters:
        matrix1 - The first matrix of doubles.
        matrix2 - The second matrix of doubles.
        Returns:
        A new matrix of doubles.
        See Also:
        multiplyElements(double[][], double[][])
      • multiplyElements

        public static final double[][] multiplyElements​(double[][] matrix1,
                                                        double[][] matrix2)
        Return a new matrix that is constructed by element by element multiplication of the two matrix arguments. If the two matrices are not the same size, throw an IllegalArgumentException.

        Note that this method does pointwise matrix multiplication. See multiply(double[][], double[][]) for standard matrix multiplication.

      • negative

        public static final double[][] negative​(double[][] matrix)
        Return a new matrix that is the additive inverse of the argument matrix.
      • orthogonalizeColumns

        public static final double[][] orthogonalizeColumns​(double[][] matrix)
        Return a new matrix that is formed by orthogonalizing the columns of the input matrix (the column vectors are orthogonal). If not all columns are linearly independent, the output matrix will contain a column of zeros for all redundant input columns.
      • orthogonalizeRows

        public static final double[][] orthogonalizeRows​(double[][] matrix)
        Return a new matrix that is formed by orthogonalizing the rows of the input matrix (the row vectors are orthogonal). If not all rows are linearly independent, the output matrix will contain a row of zeros for all redundant input rows.
      • orthonormalizeColumns

        public static final double[][] orthonormalizeColumns​(double[][] matrix)
        Return a new matrix that is formed by orthonormalizing the columns of the input matrix (the column vectors are orthogonal and have norm 1). If not all columns are linearly independent, the output matrix will contain a column of zeros for all redundant input columns.
      • orthonormalizeRows

        public static final double[][] orthonormalizeRows​(double[][] matrix)
        Return a new matrix that is formed by orthonormalizing the rows of the input matrix (the row vectors are orthogonal and have norm 1). If not all rows are linearly independent, the output matrix will contain a row of zeros for all redundant input rows.
      • qr

        public static final double[][][] qr​(double[][] matrix)
        Return a pair of matrices that are the decomposition of the input matrix (which must have linearly independent column vectors), which is m x n, into the matrix product of Q, which is m x n with orthonormal column vectors, and R, which is an invertible n x n upper triangular matrix.
        Parameters:
        matrix - The input matrix of doubles.
        Returns:
        The pair of newly allocated matrices of doubles, out[0] = Q, out[1] = R.
        Throws:
        java.lang.IllegalArgumentException - if the columns vectors of the input matrix are not linearly independent.
      • subtract

        public static final double[][] subtract​(double[][] matrix1,
                                                double[][] matrix2)
        Return a new matrix that is constructed from the argument by subtracting the second matrix from the first one. If the two matrices are not the same size, throw an IllegalArgumentException.
      • sum

        public static final double sum​(double[][] matrix)
        Return the sum of the elements of a matrix.
        Returns:
        The sum of the elements of the matrix.
      • toComplexMatrix

        public static final Complex[][] toComplexMatrix​(double[][] matrix)
        Return a new matrix that is formed by converting the doubles in the argument matrix to complex numbers. Each complex number has real part equal to the value in the argument matrix and a zero imaginary part.
        Parameters:
        matrix - An matrix of double.
        Returns:
        A new matrix of complex numbers.
      • toFloatMatrix

        public static final float[][] toFloatMatrix​(double[][] matrix)
        Return a new matrix that is formed by converting the doubles in the argument matrix to floats.
        Parameters:
        matrix - An matrix of double.
        Returns:
        A new matrix of floats.
      • toIntegerMatrix

        public static final int[][] toIntegerMatrix​(double[][] matrix)
        Return a new matrix that is formed by converting the doubles in the argument matrix to integers.
        Parameters:
        matrix - An matrix of double.
        Returns:
        A new matrix of integers.
      • toLongMatrix

        public static final long[][] toLongMatrix​(double[][] matrix)
        Return a new matrix that is formed by converting the doubles in the argument matrix to longs.
        Parameters:
        matrix - An matrix of double.
        Returns:
        A new matrix of longs.
      • toMatrixFromArray

        public static final double[][] toMatrixFromArray​(double[] array,
                                                         int rows,
                                                         int cols)
        Return a new matrix of doubles that is initialized from a 1-D array. The format of the array must be (0, 0), (0, 1), ..., (0, n-1), (1, 0), (1, 1), ..., (m-1, n-1) where the output matrix is to be m x n and entries are denoted by (row, column).
        Parameters:
        array - An array of doubles.
        rows - An integer representing the number of rows of the new matrix.
        cols - An integer representing the number of columns of the new matrix.
        Returns:
        A new matrix of doubles.
      • toString

        public static final java.lang.String toString​(double[][] matrix)
        Return a new String representing the matrix, formatted as in Java array initializers.
      • toString

        public static final java.lang.String toString​(double[][] matrix,
                                                      java.lang.String elementDelimiter,
                                                      java.lang.String matrixBegin,
                                                      java.lang.String matrixEnd,
                                                      java.lang.String vectorBegin,
                                                      java.lang.String vectorDelimiter,
                                                      java.lang.String vectorEnd)
        Return a new String representing the matrix, formatted as specified by the ArrayStringFormat argument. To get a String in the Ptolemy expression language format, call this method with ArrayStringFormat.exprASFormat as the format argument.
      • trace

        public static final double trace​(double[][] matrix)
        Return the trace of a square matrix, which is the sum of the diagonal entries A11 + A22 + ... + Ann Throw an IllegalArgumentException if the matrix is not square. Note that the trace of a matrix is equal to the sum of its eigenvalues.
      • transpose

        public static final double[][] transpose​(double[][] matrix)
        Return a new matrix that is constructed by transposing the input matrix. If the input matrix is m x n, the output matrix will be n x m.
      • within

        public static final boolean within​(double[][] matrix1,
                                           double[][] matrix2,
                                           double distance)
        Return true if the elements of the two matrices differ by no more than the specified distance. The specified distance must be non-negative. If distance is negative, return false.
        Parameters:
        matrix1 - The first matrix.
        matrix2 - The second matrix.
        distance - The distance to use for comparison.
        Returns:
        True if the elements of the two matrices are within the specified distance.
        Throws:
        java.lang.IllegalArgumentException - If the matrices do not have the same dimension. This is a run-time exception, so it need not be declared explicitly.
      • within

        public static final boolean within​(double[][] matrix1,
                                           double[][] matrix2,
                                           double[][] errorMatrix)
        Return true if the elements of the two matrices differ by no more than the specified distances. The specified distances must all be non-negative. If any element of errorMatrix is negative, return false.
        Parameters:
        matrix1 - The first matrix.
        matrix2 - The second matrix.
        errorMatrix - The distance to use for comparison. Note that if errorMatrix contains an element that is negative, then this method will return false.
        Returns:
        True if the elements of the two matrices are within the specified distance.
        Throws:
        java.lang.IllegalArgumentException - If the matrices do not have the same dimension. This is a run-time exception, so it need not be declared explicitly.
      • _checkSameDimension

        protected static final void _checkSameDimension​(java.lang.String caller,
                                                        double[][] matrix1,
                                                        double[][] matrix2)
                                                 throws java.lang.IllegalArgumentException
        Check that the two matrix arguments are of the same dimension. If they are not, an IllegalArgumentException is thrown.
        Parameters:
        caller - A string representing the caller method name.
        matrix1 - A matrix of doubles.
        matrix2 - A matrix of doubles.
        Throws:
        java.lang.IllegalArgumentException - If the arguments do not have the same dimension. This is a run-time exception, so it need not be declared explicitly.
      • _checkSquare

        protected static final int _checkSquare​(java.lang.String caller,
                                                double[][] matrix)
                                         throws java.lang.IllegalArgumentException
        Check that the argument matrix is a square matrix. If the matrix is not square, an IllegalArgumentException is thrown.
        Parameters:
        caller - A string representing the caller method name.
        matrix - A matrix of doubles.
        Returns:
        The dimension of the square matrix.
        Throws:
        java.lang.IllegalArgumentException - If the argument is not square. This is a run-time exception, so it need not be declared explicitly.
      • _columns

        protected static final int _columns​(double[][] matrix)
        Return the number of columns of a matrix.
        Parameters:
        matrix - The matrix.
        Returns:
        The number of columns.
      • _dimensionString

        protected static final java.lang.String _dimensionString​(double[][] matrix)
        Return a string that describes the number of rows and columns.
        Parameters:
        matrix - The matrix that is to be described.
        Returns:
        a string describing the dimensions of this matrix.
      • _orthogonalizeRows

        protected static final java.lang.Object[] _orthogonalizeRows​(double[][] rowArrays)
        Given a set of row vectors rowArrays[0] ... rowArrays[n-1], compute :
        1. A new set of row vectors out[0] ... out[n-1] which are the orthogonalized versions of each input row vector. If a row vector rowArray[i] is a linear combination of the last 0 .. i - 1 row vectors, set array[i] to an array of 0's (array[i] being the 0 vector is a special case of this). Put the result in returnValue[0].
        2. An n x n matrix containing the dot products of the input row vectors and the output row vectors, dotProductMatrix[j][i] = <rowArray[i], outArray[j]>. Put the result in returnValue[1].
        3. An array containing 1 / (norm(outArray[i])2), with n entries. Put the result in returnValue[2].
        4. A count of the number of rows that were found to be linear combinations of previous rows. Replace those rows with rows of zeros. The count is equal to the nullity of the transpose of the input matrix. Wrap the count with an Integer, and put it in returnValue[3].
        Orthogonalization is done with the Gram-Schmidt process.
      • _rows

        protected static final int _rows​(double[][] matrix)
        Return the number of rows of a matrix.
        Parameters:
        matrix - The matrix.
        Returns:
        The number of rows.