public class Matrix
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected int |
col |
static int |
DIAGONAL |
protected double[][] |
Elem |
static int |
FULL |
static int |
LOWER_TRIANGULAR |
protected int |
row |
static int |
SPARSE |
static int |
SYMMETRIC |
protected int |
type_d |
static int |
UPPER_TRIANGULAR |
Constructor and Description |
---|
Matrix() |
Modifier and Type | Method and Description |
---|---|
void |
addMatrix(Matrix A)
This routine adds two matrices
|
void |
addMatrixElements(double val_a)
This routine adds a double value to every element in a matrix
|
boolean |
addToColumn(double[] vec_a,
int size,
int col_index)
add the array to a specific column of matrix
|
boolean |
addToRow(double[] vec_a,
int size,
int row_index)
add the array to a specific row of matrix
|
boolean |
choleskySolve(Matrix out_vec_a,
Matrix l_a,
Matrix in_vec_a)
This method solves the linear equation l * l' * x = b, where L is the
cholesky decomposition matrix and b is an input vector.
|
boolean |
copyColumns(Matrix dstn,
int col_start,
int num_cols)
copy specified number of columns into another matrix
|
void |
copyLowerMatrix(Matrix A)
this routine copies the lower triangle of a matrix
|
void |
copyMatrix(Matrix A)
This routine takes a matrix as an argument and copies it to the
the matrix object that invoked it
|
void |
copyMatrixRows(Matrix A,
boolean[] flags_a)
This routine takes a matrix as an argument and copies its rows to the
the matrix object that invoked it only for columns that the flags are
true.
|
boolean |
copyRows(Matrix dstn,
int row_start,
int num_rows)
copy row blocks into another matrix
|
boolean |
decompositionCholesky(Matrix l_a)
this method constructs the Cholesky decomposition of an input matrix:
W.
|
void |
dimenMatrix()
Prints the matrix dimensions to STDOUT
|
void |
expMatrix()
This routine takes every element to its exponent with Math.exp()
|
boolean |
gausRandGen(Matrix A)
this routine is a gaussian random generator
Matrix of row, col dimension, mean, std deviation will be passed
input will be a matrix with (means, std deviation)
|
void |
gaussj(double[][] a,
int n,
double[][] b,
int m)
This routine computes the inverse matrix using the gauss jordan method
see numerical recipes, the are of scientific computing, second edition,
cambridge university press.
|
double |
getColSumSquare(int col_a)
this routine computes the sum of a column
|
boolean |
getColumn(double[] vec_a,
int size,
int col_index)
retrieve a column into an array
|
void |
getDiagonalVector(java.util.Vector<java.lang.Double> vec_a)
Puts the diagonal of a matrix in the vector passed
|
int |
getNumColumns()
Gets the number of Columns
|
int |
getNumRows()
Gets the number of Rows
|
boolean |
getRow(double[] vec_a,
int size,
int row_index)
retrieve a row into an array
|
double |
getValue(int r,
int c)
gets value at indexed row and column
|
void |
identityMatrix()
This routine makes an identity matrix
|
void |
initDiagonalMatrix(java.util.Vector<java.lang.Double> vec_a)
Creates a diagonal matrix of values specified by the input vector
|
void |
initMatrix(double[][] initVal,
int r,
int c)
this method initializes matrix to be the values of the 2-d array passed
|
void |
initMatrix(java.util.Vector<java.lang.Double> vec_a)
Creates a 1 row matrix of values specified by the input vector
|
void |
initMatrixValue(int r,
int c,
double value_a,
int type_a)
this method initialize the matrix to all r x n elements being the
double value passed
|
void |
inverseMatrixElements()
This routine inverses every element of the matrix
|
void |
invertMatrix(Matrix A)
this routine computes the inverse of a matrix
|
void |
mean(Matrix B)
This routine calculate the mean of a matrix
|
void |
multMatrix(Matrix A,
Matrix B)
This routine multipies two matrices
|
void |
normMatrix()
This routine takes the square root of the matrix object
|
static void |
printDoubleVector(java.util.Vector<java.lang.Double> vec_a)
Puts the DoubleVector contents in a vector and calls printMatrix()
|
void |
printMatrix()
Prints the matrix contents to STDOUT
|
void |
resetMatrix()
This routine takes a matrix as an argument and copies it to the
the matrix object that invoked it
|
void |
scalarMultMatrix(double scalar)
This routine multiplies a matrix with a scalar
|
boolean |
setColumn(double[] vec_a,
int size,
int col_index)
set a column from an array
|
void |
setColumn(int c,
double value_a)
sets the value given column index to the double value passed
works for square matrix only
|
void |
setDiagonal(double value_a)
sets the value of diagonal index to the double value passed
matrix assumed to be square
|
boolean |
setRow(double[] vec_a,
int size,
int row_index)
retrieve a row into an array
|
void |
setRow(int r,
double value_a)
sets the value given row index to the double value passed
|
void |
setValue(int r,
int c,
double value_a)
sets the value given row and column index to the double value passed
|
void |
sqrtMatrix(Matrix result_M)
finds square root of a matrix using
Denman-Beavers square root iteration,
|
boolean |
subFromColumn(double[] vec_a,
int size,
int col_index)
subtract the matrix with input array at the specific column
|
boolean |
subFromRow(double[] vec_a,
int size,
int row_index)
subtract the matrix with input array to a specific row of matrix
|
void |
subtractMatrix(Matrix A,
Matrix B)
This routine subtracts two matrices
|
void |
sutractScalarMatrix(Matrix sub_M,
double scalar)
this routine subtracts a scalar value from each element of a matrix
|
void |
toDoubleVector(java.util.Vector<java.lang.Double> vec_a)
Given a column or row matrix the values can be put into a vector
|
void |
transposeMatrix(Matrix B)
This routine performs the transpose of a matrix
|
public static final int FULL
public static final int DIAGONAL
public static final int SYMMETRIC
public static final int LOWER_TRIANGULAR
public static final int UPPER_TRIANGULAR
public static final int SPARSE
protected int row
protected int col
protected int type_d
protected double[][] Elem
public int getNumRows()
public int getNumColumns()
public void copyLowerMatrix(Matrix A)
A
- inverse matrixpublic double getColSumSquare(int col_a)
col_a
- column number to be summedpublic void setValue(int r, int c, double value_a)
r
- number of rows in the matrixc
- number of columns in the matrixvalue_a
- input set of pointspublic void setRow(int r, double value_a)
r
- row in the matrixvalue_a
- input set of pointspublic void setColumn(int c, double value_a)
c
- column in the matrixvalue_a
- input set of pointspublic void setDiagonal(double value_a)
value_a
- input set of pointspublic double getValue(int r, int c)
r
- number of rows in the matrixc
- number of columns in the matrixpublic void initMatrixValue(int r, int c, double value_a, int type_a)
r
- number of rows in the matrixc
- number of columns in the matrixvalue_a
- double value to initialize all elements of matrixtype_a
- integer value of typepublic void initMatrix(double[][] initVal, int r, int c)
initVal
- 2-dimensional array to be copyiedr
- number of rows in the matrixc
- number of columns in the matrixpublic void initMatrix(java.util.Vector<java.lang.Double> vec_a)
vec_a
- values to be put in matrixpublic void initDiagonalMatrix(java.util.Vector<java.lang.Double> vec_a)
vec_a
- values to be put in matrixpublic void getDiagonalVector(java.util.Vector<java.lang.Double> vec_a)
vec_a
- Vector for values to be added from diagonal of a matrixpublic void toDoubleVector(java.util.Vector<java.lang.Double> vec_a)
vec_a
- Vector for values to be added from column or row matrixpublic void copyMatrix(Matrix A)
A
- input matrix to be copiedpublic void copyMatrixRows(Matrix A, boolean[] flags_a)
A
- input matrix to be copiedflags_a
- 2-dimensional array of boolean variables to tell which
elements to copypublic void identityMatrix()
public boolean gausRandGen(Matrix A)
A
- a matrix containing mean and std devpublic boolean choleskySolve(Matrix out_vec_a, Matrix l_a, Matrix in_vec_a)
out_vec_a
- output vector of matrix typel_a
- lower triangular matrix cholesky decomposition marixin_vec_a
- input vector of matrix typepublic boolean decompositionCholesky(Matrix l_a)
l_a
- output lower triangular matrixpublic void gaussj(double[][] a, int n, double[][] b, int m)
a
- input matrix as 2-d double arrayn
- number of rows and columns in the input matrixb
- output matrix as 2-d double arraym
- number of rows and columns in the output matrixpublic void invertMatrix(Matrix A)
A
- inverse matrixpublic void resetMatrix()
public void addMatrix(Matrix A)
A
- matrix to be added to object evokedpublic void subtractMatrix(Matrix A, Matrix B)
A
- input matrixB
- difference matrixpublic void scalarMultMatrix(double scalar)
scalar
- matrix double scalar valuepublic void sutractScalarMatrix(Matrix sub_M, double scalar)
scalar
- double scalar value to be subtractedpublic void normMatrix()
public void expMatrix()
public void inverseMatrixElements()
public void addMatrixElements(double val_a)
val_a
- double value to be added to every elementpublic void multMatrix(Matrix A, Matrix B)
A
- input matrixB
- product matrixpublic void transposeMatrix(Matrix B)
B
- matrix transposepublic void mean(Matrix B)
B
- matrixpublic void printMatrix()
public static void printDoubleVector(java.util.Vector<java.lang.Double> vec_a)
vec_a
- Vector to be printedpublic void dimenMatrix()
public void sqrtMatrix(Matrix result_M)
result_M
- square root of a matrixpublic boolean addToColumn(double[] vec_a, int size, int col_index)
vec_a
- array to be addedcol_index
- column index of a matrixpublic boolean addToRow(double[] vec_a, int size, int row_index)
vec_a
- array to be addedrow_index
- row index of a matrixpublic boolean subFromColumn(double[] vec_a, int size, int col_index)
vec_a
- array to be addedcol_index
- column index of a matrixpublic boolean subFromRow(double[] vec_a, int size, int row_index)
vec_a
- array to be subtractedrow_index
- row index of a matrixpublic boolean getColumn(double[] vec_a, int size, int col_index)
vec_a
- an array accepting the columnpublic boolean setColumn(double[] vec_a, int size, int col_index)
vec_a
- an array accepting the columnpublic boolean getRow(double[] vec_a, int size, int row_index)
vec_a
- an array accepting the rowpublic boolean setRow(double[] vec_a, int size, int row_index)
vec_a
- an array accepting the rowpublic boolean copyRows(Matrix dstn, int row_start, int num_rows)
dstn
- destination matrixrow_start
- row index of this matrix from where the copy
startsnum_rows
- number of rows to be copiedpublic boolean copyColumns(Matrix dstn, int col_start, int num_cols)
dstn
- destination matrixcol_start
- column index of this matrix from where the copy
startsnum_cols
- number of columns to be copied