Class Matrix

java.lang.Object
  |
  +--Matrix

class Matrix
extends java.lang.Object


Field Summary
private  double[][] matrix
           
 
Constructor Summary
Matrix(double[][] data)
          Construct a new vector with the given double values.
Matrix(int rowNum, int colNum)
          Construct a new matrix with rowNum rows and colNum columns.
 
Method Summary
 Matrix add(Matrix other)
          Adds the other matrix to the current matrix and returns the result in a new Matrix object.
 double elementAt(int i, int j)
          Returns the value in the i'th row and j’th column in the matrix..
 AlgebraicVector gaussElimination()
          Retruns a vector that is the solution of the set of equations defined by this augmented matrix.
 int getColNum()
          Returns the number of columns in the matrix.
 AlgebraicVector getColVector(int i)
          Returns the i'th column in the matrix as an AlgebraicVector object.
 int getRowNum()
          Returns the number of rows in the matrix.
 AlgebraicVector[] getRowsAsVectors()
          Returns the rows of the matrix as an array of AlgebraicVectors
 AlgebraicVector getRowVector(int i)
          Returns the i'th row in the matrix as an AlgebraicVector object.
 AlgebraicVector mul(AlgebraicVector other)
          Computes the multiplication of the current matrix with the given vector.
 Matrix mul(double scalar)
          Computes the multiplication of the current matrix with the given scalar.
 Matrix mul(Matrix other)
          Multiplies the other matrix to the current matrix and returns the result in a new Matrix object.
 void setElementAt(double value, int i, int j)
          Sets the element in the i'th row and the j’th column to value.
 void setRowVector(AlgebraicVector vec, int i)
          Replace row i in the matrix with the given vector Assumes dimension of vector equal to the number of cols
 Matrix sub(Matrix other)
          Substracts the other matrix to the current matrix and returns the result in a new Matrix object.
private  void swapRows(int i, int j)
          Swaps between 2 rows in the matrix.
 java.lang.String toString()
          Returns a string representation of the vector in the following format: 2.0 3.1 5.4
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

matrix

private double[][] matrix
Constructor Detail

Matrix

public Matrix(int rowNum,
              int colNum)
Construct a new matrix with rowNum rows and colNum columns. Initial values are set to zero
Parameters:
rowNum - Number of Rows
colNum - Number of cols

Matrix

public Matrix(double[][] data)
Construct a new vector with the given double values.
Parameters:
data - A 2-dimentionl array of doubles
Method Detail

elementAt

public double elementAt(int i,
                        int j)
Returns the value in the i'th row and j’th column in the matrix.. Assumes that the indices i and j are legal, i.e 0
Parameters:
i - row i
j - col j
Returns:
double value found in (i,j) in the matrix

setElementAt

public void setElementAt(double value,
                         int i,
                         int j)
Sets the element in the i'th row and the j’th column to value. Assumes that the indices i and j are legal, i.e 0
Parameters:
value - value you want inserted in
i - row i
j - col j

getRowNum

public int getRowNum()
Returns the number of rows in the matrix.
Returns:
int the number of rows in matrix

getColNum

public int getColNum()
Returns the number of columns in the matrix.
Returns:
int the number of cols in matrix

getRowVector

public AlgebraicVector getRowVector(int i)
Returns the i'th row in the matrix as an AlgebraicVector object. Assumes i is legal.
Parameters:
i - the row in the matrix you want back as vector
Returns:
AlgebraicVector the row i as AlgebraicVector

getColVector

public AlgebraicVector getColVector(int i)
Returns the i'th column in the matrix as an AlgebraicVector object. Assumes i is legal.
Parameters:
i - the col in the matrix you want back as vector
Returns:
AlgebraicVector the col i as AlgebraicVector

getRowsAsVectors

public AlgebraicVector[] getRowsAsVectors()
Returns the rows of the matrix as an array of AlgebraicVectors
Returns:
AlgebraicVector[] an Array of vectors with all the matrix

add

public Matrix add(Matrix other)
Adds the other matrix to the current matrix and returns the result in a new Matrix object. Assumes that the other Matrix has the same dimensions as the current matrix.
Parameters:
other - the matrix you want tho add
Returns:
matrix the sum of the 2 matrices

sub

public Matrix sub(Matrix other)
Substracts the other matrix to the current matrix and returns the result in a new Matrix object. Assumes that the other Matrix has the same dimensions as the current matrix.
Parameters:
other - the matrix you want tho substract
Returns:
matrix the substraction of the 2 matrices

mul

public Matrix mul(Matrix other)
Multiplies the other matrix to the current matrix and returns the result in a new Matrix object. Assumes that the other Matrix’s number of rows equals the current matrixe’s number of columns.
Parameters:
other - the matrix you want to multiply
Returns:
matrix the multiplication of the 2 matrices

mul

public Matrix mul(double scalar)
Computes the multiplication of the current matrix with the given scalar. Returns the result in a new Matrix object.
Parameters:
scalar - a scalar you want to multiply
Returns:
matrix the multiplication of the matrix with the scalar

mul

public AlgebraicVector mul(AlgebraicVector other)
Computes the multiplication of the current matrix with the given vector. Returns the result in a new AlgebraicVector object. Assumes the the dimension of other equals the number of columns in the current matrix.
Parameters:
other - a vector you want to multiply
Returns:
AlgebraicVector mult. of the matrix with vector

setRowVector

public void setRowVector(AlgebraicVector vec,
                         int i)
Replace row i in the matrix with the given vector Assumes dimension of vector equal to the number of cols
Parameters:
vec - AlgebraicVector containing the vector to set
i - The row number to replace with the given vector

swapRows

private void swapRows(int i,
                      int j)
Swaps between 2 rows in the matrix.
Parameters:
i - row i
j - row j

gaussElimination

public AlgebraicVector gaussElimination()
Retruns a vector that is the solution of the set of equations defined by this augmented matrix. If the equations are not solvable returns null.
Returns:
AlgebraicVector vector with the solution to the matrix if possible (null if no solution)

toString

public java.lang.String toString()
Returns a string representation of the vector in the following format: 2.0 3.1 5.4
Overrides:
toString in class java.lang.Object