Package ucar.ma2
Class MAMatrix
java.lang.Object
ucar.ma2.MAMatrix
Abstraction for matrix operations.
A matrix is a rank-2 Array: m[rows, cols].
All operations done in double precision
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncolumn(int j) Get the jth column, return as a MAVector: same backing store.copy()Create a new MAMatrix that is the same as this one, with a copy of the backing store.Dot product of matrix and vector: return M dot vdoublegetDouble(int i, int j) intgetNcols()intgetNrows()static MAMatrixMatrix multiply: return m1 * m2.voidpostMultiplyDiagonal(MAVector diag) Matrix multiply by a diagonal matrix, store result in this: this = this * diagvoidpreMultiplyDiagonal(MAVector diag) Matrix multiply by a diagonal matrix, store result in this: this = diag * thisrow(int i) Get the ith row, return as a MAVector: same backing store.voidsetDouble(int i, int j, double val) Create a MAMatrix that is the transpose of this one, with the same backing store.
-
Constructor Details
-
MAMatrix
public MAMatrix(int nrows, int ncols) Create an MAMatrix of the given shape.- Parameters:
nrows- number of rowsncols- number of cols
-
MAMatrix
Create an MAMatrix using the given rank-2 array.- Parameters:
a- rank-2 array- Throws:
IllegalArgumentException- is a is not rank 2
-
-
Method Details
-
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
Create a new MAMatrix that is the same as this one, with a copy of the backing store. -
transpose
Create a MAMatrix that is the transpose of this one, with the same backing store. Use copy() to get a copy. -
column
Get the jth column, return as a MAVector: same backing store. -
row
Get the ith row, return as a MAVector: same backing store. -
dot
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
Matrix multiply: return m1 * m2.- Parameters:
m1- left matrixm2- right matrix- Returns:
- MAMatrix result: new matrix
- Throws:
IllegalArgumentException- if m1.getNcols() != m2.getNrows().
-
postMultiplyDiagonal
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
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().
-