Class SymmetricMatrix

    • Constructor Detail

      • SymmetricMatrix

        public SymmetricMatrix​(int dim)
        Construct a symmetric matrix of dimension dim * dim.
        Parameters:
        dim - the matrix dimension
      • SymmetricMatrix

        public SymmetricMatrix​(double[][] data)
        Construct a symmetric matrix from a 2D double[][] array. The array specifies only the lower triangular part (main diagonal inclusive) of the whole matrix. For example,
                 new double[][]{
                          {1},
                          {2, 3},
                          {4, 5, 6},
                          {7, 8, 9, 10},
                          {11, 12, 13, 14, 15}});
         
        gives \[ \begin{bmatrix} 1 & 2 & 4 & 7 & 11\\ 2 & 3 & 5 & 8 & 12\\ 4 & 5 & 6 & 9 & 13\\ 7 & 8 & 9 & 10 & 14\\ 11 & 12 & 13 & 14 & 15 \end{bmatrix} \] This constructor uses lower instead of upper triangular representation for visual reason.
        Parameters:
        data - the lower triangular specification
      • SymmetricMatrix

        public SymmetricMatrix​(Matrix A)
        Cast an (almost) symmetric matrix into SymmetricMatrix by averaging A(i,j) and A(j,i).
        Parameters:
        A - an (almost) symmetric matrix
      • SymmetricMatrix

        public SymmetricMatrix​(Matrix A,
                               boolean copyLower)
        Cast an (almost) symmetric matrix into SymmetricMatrix.
        Parameters:
        A - an (almost) symmetric matrix
        copyLower - true if the lower triangular portion of A is used; otherwise, the average values of A(i,j) and A(j,i) are used
      • SymmetricMatrix

        public SymmetricMatrix​(SymmetricMatrix S)
        Copy constructor.
        Parameters:
        S - a symmetric 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
      • deepCopy

        public SymmetricMatrix deepCopy()
        Description copied from interface: DeepCopyable
        The implementation returns an instance created from this by the copy constructor of the class, or just this if the instance itself is immutable.
        Specified by:
        deepCopy in interface DeepCopyable
        Specified by:
        deepCopy in interface Matrix
        Returns:
        an independent (deep) copy of the instance
      • set

        public void set​(int row,
                        int col,
                        double value)
                 throws MatrixAccessException
        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:
        row - the row index
        col - the column index
        value - the value to set A[i,j] to
        Throws:
        MatrixAccessException - if i or j is out of range
      • getRow

        public Vector getRow​(int i)
                      throws MatrixAccessException
        Description copied from interface: Matrix
        Get the specified row in the matrix as a vector.
        Specified by:
        getRow in interface Matrix
        Parameters:
        i - the row index
        Returns:
        the vector A[i, ]
        Throws:
        MatrixAccessException - when i < 1, or when i > the number of rows
      • getColumn

        public Vector getColumn​(int j)
                         throws MatrixAccessException
        Description copied from interface: Matrix
        Get the specified column in the matrix as a vector.
        Specified by:
        getColumn in interface Matrix
        Parameters:
        j - the column index
        Returns:
        a vector A[, j]
        Throws:
        MatrixAccessException - when j < 1, or when j > the number of columns
      • t

        public SymmetricMatrix t()
        The transpose of a symmetric matrix is the same as itself.
        Specified by:
        t in interface MatrixRing
        Returns:
        a copy of itself
      • scaled

        public SymmetricMatrix scaled​(double scalar)
        Description copied from interface: Matrix
        Scale this matrix, A, by a constant.
        Specified by:
        scaled in interface Matrix
        Parameters:
        scalar - a double
        Returns:
        cA
      • ONE

        public SymmetricMatrix ONE()
        Description copied from interface: MatrixRing
        Get an identity matrix that has the same dimension as this matrix. For a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).
        Specified by:
        ONE in interface MatrixRing
        Specified by:
        ONE in interface Monoid<Matrix>
        Returns:
        an identity matrix
      • multiply

        public Vector multiply​(Vector v)
        Description copied from interface: Matrix
        Right multiply this matrix, A, by a vector.
        Specified by:
        multiply in interface Matrix
        Parameters:
        v - a vector
        Returns:
        Av, a vector
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object