Class Matrix

java.lang.Object
  extended by Matrix

public class Matrix
extends java.lang.Object

this class represents a matrix object and performs matrix operations that are needed to compute the eigenvectors and eigenvalues


Field Summary
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 Summary
Matrix()
           
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FULL

public static final int FULL
See Also:
Constant Field Values

DIAGONAL

public static final int DIAGONAL
See Also:
Constant Field Values

SYMMETRIC

public static final int SYMMETRIC
See Also:
Constant Field Values

LOWER_TRIANGULAR

public static final int LOWER_TRIANGULAR
See Also:
Constant Field Values

UPPER_TRIANGULAR

public static final int UPPER_TRIANGULAR
See Also:
Constant Field Values

SPARSE

public static final int SPARSE
See Also:
Constant Field Values

row

protected int row

col

protected int col

type_d

protected int type_d

Elem

protected double[][] Elem
Constructor Detail

Matrix

public Matrix()
Method Detail

getNumRows

public int getNumRows()
Gets the number of Rows

Returns:
number of rows in the matrix

getNumColumns

public int getNumColumns()
Gets the number of Columns

Returns:
number of columns in the matrix

copyLowerMatrix

public void copyLowerMatrix(Matrix A)
this routine copies the lower triangle of a matrix

Parameters:
A - inverse matrix

getColSumSquare

public double getColSumSquare(int col_a)
this routine computes the sum of a column

Parameters:
col_a - column number to be summed
Returns:
double value of sum

setValue

public void setValue(int r,
                     int c,
                     double value_a)
sets the value given row and column index to the double value passed

Parameters:
r - number of rows in the matrix
c - number of columns in the matrix
value_a - input set of points

setRow

public void setRow(int r,
                   double value_a)
sets the value given row index to the double value passed

Parameters:
r - row in the matrix
value_a - input set of points

setColumn

public void setColumn(int c,
                      double value_a)
sets the value given column index to the double value passed works for square matrix only

Parameters:
c - column in the matrix
value_a - input set of points

setDiagonal

public void setDiagonal(double value_a)
sets the value of diagonal index to the double value passed matrix assumed to be square

Parameters:
value_a - input set of points

getValue

public double getValue(int r,
                       int c)
gets value at indexed row and column

Parameters:
r - number of rows in the matrix
c - number of columns in the matrix
Returns:
double value at index

initMatrixValue

public 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

Parameters:
r - number of rows in the matrix
c - number of columns in the matrix
value_a - double value to initialize all elements of matrix
type_a - integer value of type

initMatrix

public void initMatrix(double[][] initVal,
                       int r,
                       int c)
this method initializes matrix to be the values of the 2-d array passed

Parameters:
initVal - 2-dimensional array to be copyied
r - number of rows in the matrix
c - number of columns in the matrix

initMatrix

public void initMatrix(java.util.Vector<java.lang.Double> vec_a)
Creates a 1 row matrix of values specified by the input vector

Parameters:
vec_a - values to be put in matrix

initDiagonalMatrix

public void initDiagonalMatrix(java.util.Vector<java.lang.Double> vec_a)
Creates a diagonal matrix of values specified by the input vector

Parameters:
vec_a - values to be put in matrix

getDiagonalVector

public void getDiagonalVector(java.util.Vector<java.lang.Double> vec_a)
Puts the diagonal of a matrix in the vector passed

Parameters:
vec_a - Vector for values to be added from diagonal of a matrix

toDoubleVector

public void toDoubleVector(java.util.Vector<java.lang.Double> vec_a)
Given a column or row matrix the values can be put into a vector

Parameters:
vec_a - Vector for values to be added from column or row matrix

copyMatrix

public void copyMatrix(Matrix A)
This routine takes a matrix as an argument and copies it to the the matrix object that invoked it

Parameters:
A - input matrix to be copied

copyMatrixRows

public 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.

Parameters:
A - input matrix to be copied
flags_a - 2-dimensional array of boolean variables to tell which elements to copy

identityMatrix

public void identityMatrix()
This routine makes an identity matrix


gausRandGen

public 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)

Parameters:
A - a matrix containing mean and std dev
Returns:
true

choleskySolve

public 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.

Parameters:
out_vec_a - output vector of matrix type
l_a - lower triangular matrix cholesky decomposition marix
in_vec_a - input vector of matrix type
Returns:
true

decompositionCholesky

public boolean decompositionCholesky(Matrix l_a)
this method constructs the Cholesky decomposition of an input matrix: W. Press, S. Teukolsky, W. Vetterling, B. Flannery, Numerical Recipes in C, Second Edition, Cambridge University Press, New York, New York, USA, pp. 96-97, 1995. upon output, l' * l = this note that this method only operates on symmetric matrices.

Parameters:
l_a - output lower triangular matrix
Returns:
true

gaussj

public 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. pages 36 - 41

Parameters:
a - input matrix as 2-d double array
n - number of rows and columns in the input matrix
b - output matrix as 2-d double array
m - number of rows and columns in the output matrix

invertMatrix

public void invertMatrix(Matrix A)
this routine computes the inverse of a matrix

Parameters:
A - inverse matrix

resetMatrix

public void resetMatrix()
This routine takes a matrix as an argument and copies it to the the matrix object that invoked it


addMatrix

public void addMatrix(Matrix A)
This routine adds two matrices

Parameters:
A - matrix to be added to object evoked

subtractMatrix

public void subtractMatrix(Matrix A,
                           Matrix B)
This routine subtracts two matrices

Parameters:
A - input matrix
B - difference matrix

scalarMultMatrix

public void scalarMultMatrix(double scalar)
This routine multiplies a matrix with a scalar

Parameters:
scalar - matrix double scalar value

sutractScalarMatrix

public void sutractScalarMatrix(Matrix sub_M,
                                double scalar)
this routine subtracts a scalar value from each element of a matrix

Parameters:
scalar - double scalar value to be subtracted

normMatrix

public void normMatrix()
This routine takes the square root of the matrix object


expMatrix

public void expMatrix()
This routine takes every element to its exponent with Math.exp()


inverseMatrixElements

public void inverseMatrixElements()
This routine inverses every element of the matrix


addMatrixElements

public void addMatrixElements(double val_a)
This routine adds a double value to every element in a matrix

Parameters:
val_a - double value to be added to every element

multMatrix

public void multMatrix(Matrix A,
                       Matrix B)
This routine multipies two matrices

Parameters:
A - input matrix
B - product matrix

transposeMatrix

public void transposeMatrix(Matrix B)
This routine performs the transpose of a matrix

Parameters:
B - matrix transpose

mean

public void mean(Matrix B)
This routine calculate the mean of a matrix

Parameters:
B - matrix

printMatrix

public void printMatrix()
Prints the matrix contents to STDOUT


printDoubleVector

public static void printDoubleVector(java.util.Vector<java.lang.Double> vec_a)
Puts the DoubleVector contents in a vector and calls printMatrix()

Parameters:
vec_a - Vector to be printed

dimenMatrix

public void dimenMatrix()
Prints the matrix dimensions to STDOUT


sqrtMatrix

public void sqrtMatrix(Matrix result_M)
finds square root of a matrix using Denman-Beavers square root iteration,

Parameters:
result_M - square root of a matrix

addToColumn

public boolean addToColumn(double[] vec_a,
                           int size,
                           int col_index)
add the array to a specific column of matrix

Parameters:
vec_a - array to be added
col_index - column index of a matrix

addToRow

public boolean addToRow(double[] vec_a,
                        int size,
                        int row_index)
add the array to a specific row of matrix

Parameters:
vec_a - array to be added
row_index - row index of a matrix

subFromColumn

public boolean subFromColumn(double[] vec_a,
                             int size,
                             int col_index)
subtract the matrix with input array at the specific column

Parameters:
vec_a - array to be added
col_index - column index of a matrix

subFromRow

public boolean subFromRow(double[] vec_a,
                          int size,
                          int row_index)
subtract the matrix with input array to a specific row of matrix

Parameters:
vec_a - array to be subtracted
row_index - row index of a matrix

getColumn

public boolean getColumn(double[] vec_a,
                         int size,
                         int col_index)
retrieve a column into an array

Parameters:
vec_a - an array accepting the column

setColumn

public boolean setColumn(double[] vec_a,
                         int size,
                         int col_index)
set a column from an array

Parameters:
vec_a - an array accepting the column

getRow

public boolean getRow(double[] vec_a,
                      int size,
                      int row_index)
retrieve a row into an array

Parameters:
vec_a - an array accepting the row

setRow

public boolean setRow(double[] vec_a,
                      int size,
                      int row_index)
retrieve a row into an array

Parameters:
vec_a - an array accepting the row

copyRows

public boolean copyRows(Matrix dstn,
                        int row_start,
                        int num_rows)
copy row blocks into another matrix

Parameters:
dstn - destination matrix
row_start - row index of this matrix from where the copy starts
num_rows - number of rows to be copied

copyColumns

public boolean copyColumns(Matrix dstn,
                           int col_start,
                           int num_cols)
copy specified number of columns into another matrix

Parameters:
dstn - destination matrix
col_start - column index of this matrix from where the copy starts
num_cols - number of columns to be copied