Package ucar.ma2

Class MAMatrix


  • public class MAMatrix
    extends Object
    Abstraction for matrix operations. A matrix is a rank-2 Array: m[rows, cols]. All operations done in double precision
    • Constructor Detail

      • MAMatrix

        public MAMatrix​(int nrows,
                        int ncols)
        Create an MAMatrix of the given shape.
        Parameters:
        nrows - number of rows
        ncols - number of cols
      • MAMatrix

        public MAMatrix​(Array a)
        Create an MAMatrix using the given rank-2 array.
        Parameters:
        a - rank-2 array
        Throws:
        IllegalArgumentException - is a is not rank 2
    • Method Detail

      • getNrows

        public int getNrows()
      • getNcols

        public int getNcols()
      • getDouble

        public double getDouble​(int i,
                                int j)
      • setDouble

        public void setDouble​(int i,
                              int j,
                              double val)
      • copy

        public MAMatrix copy()
        Create a new MAMatrix that is the same as this one, with a copy of the backing store.
      • transpose

        public MAMatrix transpose()
        Create a MAMatrix that is the transpose of this one, with the same backing store. Use copy() to get a copy.
      • column

        public MAVector column​(int j)
        Get the jth column, return as a MAVector: same backing store.
      • row

        public MAVector row​(int i)
        Get the ith row, return as a MAVector: same backing store.
      • dot

        public MAVector dot​(MAVector v)
        Dot product of matrix and vector: return M dot v
        Parameters:
        v - dot product with this vector
        Returns:
        MAVector result: new vector
        Throws:
        IllegalArgumentException - if ncols != v.getSize().
      • multiply

        public static MAMatrix multiply​(MAMatrix m1,
                                        MAMatrix m2)
        Matrix multiply: return m1 * m2.
        Parameters:
        m1 - left matrix
        m2 - right matrix
        Returns:
        MAMatrix result: new matrix
        Throws:
        IllegalArgumentException - if m1.getNcols() != m2.getNrows().
      • postMultiplyDiagonal

        public void postMultiplyDiagonal​(MAVector diag)
        Matrix multiply by a diagonal matrix, store result in this: this = this * diag
        Parameters:
        diag - diagonal matrix stored as a Vector
        Throws:
        IllegalArgumentException - if ncols != diag.getNelems().
      • preMultiplyDiagonal

        public void preMultiplyDiagonal​(MAVector diag)
        Matrix multiply by a diagonal matrix, store result in this: this = diag * this
        Parameters:
        diag - diagonal matrix stored as a Vector
        Throws:
        IllegalArgumentException - if nrows != diag.getNelems().