SciLib.Math
Class matrix

java.lang.Object
  extended by SciLib.Math.matrix

public class matrix
extends java.lang.Object

This class contains some methods to handle the matrix problems


Constructor Summary
matrix()
          Allocates a 0x0 matrix.
matrix(double[][] ma)
          Make a matrix from a two-dimensional array.
matrix(int rows, int columns)
          Allocates a m x n matrix.
matrix(matrix ma)
          Make a copy of a matrix ma.
 
Method Summary
 double elementAt(int i, int j)
          return the value element of matrix at row i and column j.
 vector getColumn(int j)
          return a vector that contains all elements of the jth column.
 int getColumns()
          return the number of columns.
 double[][] getData()
          return a two-dimensional array that contains all elements of matrix.
 vector getRow(int i)
          return a vector that contains all elements of the ith row.
 int getRows()
          return the number of rows.
static matrix identity(int n)
          Make the n x n identity mattrix
 double max()
          Return the maximum value of the matrix
 double min()
          Return the minimum value of the matrix
 void minus(matrix x)
          minus this matrix with the matrix x and store the result in this matrix
static matrix minus(matrix x, matrix y)
          minus two matrices x, y.
static matrix mult(matrix x, matrix y)
          Make a matrix A = x*y
static vector mult(matrix A, vector x)
          compute Ax
 void plus(matrix x)
          plus this matrix with the matrix x and store the result in this matrix
static matrix plus(matrix x, matrix y)
          plus two matrices x, y.
 void print()
          Print all elements of the matrix using System.out.
 void random(double a, double b)
          Fill this matrix with random values between a and b.
 void read(java.lang.String fileName)
          Read data from a file to a matrix.
 void resize(int rows, int columns)
          Change the size of the matrix.
 void scale(double s)
          Scaling all elements of the matrix with a factor s.
 void scaling(double a, double b)
          scaling
 matrix scaling(matrix m, double a, double b)
          scaling
 void setColumn(int i, vector v)
          set column(i) = v
 void setElementAt(double x, int i, int j)
          Change the value element of matrix at row i and column j.
 void setRow(int i, vector v)
          set row(i) = v
 matrix transpose()
          Make the transpose matrix of this matrix
static matrix transpose(matrix ma)
          Make the transpose matrix of a matrix ma
 void write(java.lang.String fileName)
          Write all elements of the matrix to a file.
 void write(java.lang.String fileName, int n)
          Write all elements of the matrix to a file with the n deimal digits format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

matrix

public matrix()
Allocates a 0x0 matrix.


matrix

public matrix(int rows,
              int columns)
Allocates a m x n matrix.

Parameters:
rows - The number of rows
columns - The number of columns

matrix

public matrix(double[][] ma)
Make a matrix from a two-dimensional array.

Parameters:
ma - A two-dimensional array

matrix

public matrix(matrix ma)
Make a copy of a matrix ma.

Parameters:
ma - A matrix
Method Detail

elementAt

public double elementAt(int i,
                        int j)
                 throws java.lang.ArrayIndexOutOfBoundsException
return the value element of matrix at row i and column j.

Parameters:
i - An integer
j - An integer
Returns:
A double value
Throws:
java.lang.ArrayIndexOutOfBoundsException

setElementAt

public void setElementAt(double x,
                         int i,
                         int j)
                  throws java.lang.ArrayIndexOutOfBoundsException
Change the value element of matrix at row i and column j.

Parameters:
i - An integer
j - An integer
x - A double value
Throws:
java.lang.ArrayIndexOutOfBoundsException

getRows

public final int getRows()
return the number of rows.

Returns:
An integer

getColumns

public final int getColumns()
return the number of columns.

Returns:
An integer

getData

public double[][] getData()
return a two-dimensional array that contains all elements of matrix.

Returns:
A two-dimensional array

resize

public void resize(int rows,
                   int columns)
Change the size of the matrix.

Parameters:
rows - The new numbers of rows
columns - The new numbers of columns

getRow

public vector getRow(int i)
return a vector that contains all elements of the ith row.

Returns:
A vector

getColumn

public vector getColumn(int j)
return a vector that contains all elements of the jth column.

Returns:
A vector

min

public final double min()
Return the minimum value of the matrix

Returns:
A double value

max

public final double max()
Return the maximum value of the matrix

Returns:
A double value

scale

public void scale(double s)
Scaling all elements of the matrix with a factor s.

Parameters:
s - A double value that is the sacling factor

random

public void random(double a,
                   double b)
Fill this matrix with random values between a and b.

Parameters:
a - A double value
b - A double value

plus

public void plus(matrix x)
          throws SizeException
plus this matrix with the matrix x and store the result in this matrix

Parameters:
x - A vector
Throws:
SizeException

plus

public static matrix plus(matrix x,
                          matrix y)
                   throws SizeException
plus two matrices x, y. The result is stored in a new matrix

Parameters:
x - A matrix
y - A matrix
Returns:
A matrix that is equal to x + y
Throws:
SizeException

minus

public void minus(matrix x)
           throws SizeException
minus this matrix with the matrix x and store the result in this matrix

Parameters:
x - A vector
Throws:
SizeException

minus

public static matrix minus(matrix x,
                           matrix y)
                    throws SizeException
minus two matrices x, y. The result is stored in a new matrix

Parameters:
x - A matrix
y - A matrix
Returns:
A matrix that is equal to x - y
Throws:
SizeException

mult

public static matrix mult(matrix x,
                          matrix y)
                   throws SizeException
Make a matrix A = x*y

Parameters:
x - A matrix
y - A matrix
Returns:
A matrix that is equal to x*y
Throws:
SizeException

mult

public static vector mult(matrix A,
                          vector x)
compute Ax

Parameters:
A - A matrix
x - A vector
Returns:
A vector

identity

public static matrix identity(int n)
Make the n x n identity mattrix

Parameters:
n - An integer
Returns:
The n x n identity mattrix

transpose

public static matrix transpose(matrix ma)
Make the transpose matrix of a matrix ma

Parameters:
ma - A matrix
Returns:
A mattrix

transpose

public matrix transpose()
Make the transpose matrix of this matrix

Returns:
A mattrix

write

public void write(java.lang.String fileName)
Write all elements of the matrix to a file.

Parameters:
fileName - A String

write

public void write(java.lang.String fileName,
                  int n)
Write all elements of the matrix to a file with the n deimal digits format.

Parameters:
fileName - A String

read

public void read(java.lang.String fileName)
Read data from a file to a matrix.

Parameters:
fileName - a String

print

public final void print()
Print all elements of the matrix using System.out.


setRow

public void setRow(int i,
                   vector v)
set row(i) = v

Parameters:
i - An integer value, the row index
v - A vector

setColumn

public void setColumn(int i,
                      vector v)
set column(i) = v

Parameters:
i - An integer value, the column index
v - A vector

scaling

public matrix scaling(matrix m,
                      double a,
                      double b)
scaling

Parameters:
m - A matrix that will be scaled
a - A double, the lower bound of all elements in the matrix
b - A double, the upper bound of all elements in the matrix
Returns:
A matrix

scaling

public void scaling(double a,
                    double b)
scaling

Parameters:
a - A double, the lower bound of all elements in the matrix
b - A double, the upper bound of all elements in the matrix