ProGAL.math
Class Matrix

java.lang.Object
  extended by ProGAL.math.Matrix
Direct Known Subclasses:
Matrix.ImmutableMatrix, Matrix3x3

public class Matrix
extends java.lang.Object


Nested Class Summary
 class Matrix.EigenvalueDecomposition
          Eigenvalues and eigenvectors of a real matrix.
static class Matrix.ImmutableMatrix
           
 
Constructor Summary
Matrix(double[][] coords)
          Construct a matrix from an array-of-array-of-double.
Matrix(int M, int N)
          Construct an M by N matrix with zeros in all entries.
Matrix(int M, int N, int seed)
           
 
Method Summary
 Matrix add(Matrix m)
          Add the components of two matrices.
 Matrix addThis(Matrix m)
          Add the components of two matrices.
 Matrix clone()
          Returns a clone of this matrix.
static Matrix create4x4ColumnMatrix(Vector v1, Vector v2, Vector v3, Vector v4)
           
static Matrix3x3 createColumnMatrix(Vector v1, Vector v2, Vector v3)
           
static Matrix createIdentityMatrix(int n)
           
static Matrix createRandomMatrix(int n)
           
static Matrix createRotationMatrix(double angle, Vector v)
           
static Matrix3x3 createRowMatrix(Vector v1, Vector v2, Vector v3)
           
 double determinant()
          Get the determinant of this matrix.
 boolean equals(Matrix m)
           
 boolean equals(java.lang.Object o)
           
 Matrix expand()
          extends to the smallest power of 2 square matrix by adding appropriate zero rows and columns
 Matrix extend()
          extends to the smallest square matrix by adding appropriate zero rows or columns
 double get(int i, int j)
           
 Vector getColumn(int c)
           
 double[][] getCoords()
           
 Matrix.EigenvalueDecomposition getEigenvalueDecomposition()
           
 int getM()
           
 int getN()
           
 Vector getRow(int r)
           
 Matrix getSubmatrix(int i1, int i2, int j1, int j2)
           
 Matrix getTranspose()
          Get the transpose of this matrix
 Matrix invert()
          Return the inverse of this matrix.
 Matrix invertThis()
          Invert this matrix (overwrites this and returns it).
 boolean isSquare()
           
 Matrix minor(int r, int c)
          Return the minor, i.e.
 Matrix multiply_Strassen(Matrix B)
           
 Matrix multiply(double scalar)
          Multiply the components of this matrix by a scalar.
 Matrix multiply(Matrix m)
          Multiply this matrix to another matrix and return the result.
 Point multiply(Point p)
          Apply this matrix to the point p and return the result (this will NOT change p).
 Point multiply(Point p)
           
 Vector multiply(Vector v)
          Apply this matrix to the vector v and return the result (without changing v).
 Point multiplyIn(Point p)
          Apply this matrix to the point p and return the result (this will change p).
 Vector multiplyIn(Vector v)
          Apply this matrix to the vector v and return the result (this will change v).
 Matrix multiplyThis(double scalar)
          Multiply the components of this matrix by a scalar.
 Matrix multiplyThis(Matrix m)
          Multiply this matrix to another matrix.
 Matrix orthonormalizeThis()
          Run Gram-Schmidt orthonormalization procedure.
 Matrix reduce()
          Reduce this matrix to row canonical form (reduced row echelon form).
 Matrix reduceThis()
          Reduce this matrix to row canonical form (reduced row echelon form).
 void set(int r, int c, double v)
           
 void setColumn(int c, Vector v)
           
 void setRow(int r, Vector v)
           
 void setSubmatrix(int i1, int j1, Matrix M)
           
 Matrix subtract(Matrix m)
          Subtract the components of two matrices.
 Matrix subtractThis(Matrix m)
          Subtract the components of two matrices.
 void toConsole()
           
 void toConsole(int dec)
           
 java.lang.String toString()
           
 java.lang.String toString(int dec)
           
 Matrix transpose()
          Get the transpose of this matrix
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Matrix

public Matrix(int M,
              int N)
Construct an M by N matrix with zeros in all entries.


Matrix

public Matrix(double[][] coords)
Construct a matrix from an array-of-array-of-double. The array should index rows first and columns next. The results are undefined if the number of elements in each row-array are different.


Matrix

public Matrix(int M,
              int N,
              int seed)
Method Detail

set

public void set(int r,
                int c,
                double v)

get

public double get(int i,
                  int j)

getCoords

public double[][] getCoords()

getM

public int getM()

getN

public int getN()

getRow

public Vector getRow(int r)

getColumn

public Vector getColumn(int c)

setRow

public void setRow(int r,
                   Vector v)

setColumn

public void setColumn(int c,
                      Vector v)

getSubmatrix

public Matrix getSubmatrix(int i1,
                           int i2,
                           int j1,
                           int j2)

setSubmatrix

public void setSubmatrix(int i1,
                         int j1,
                         Matrix M)

getTranspose

public Matrix getTranspose()
Get the transpose of this matrix


transpose

public Matrix transpose()
Get the transpose of this matrix


multiplyIn

public Vector multiplyIn(Vector v)
Apply this matrix to the vector v and return the result (this will change v).


multiply

public Point multiply(Point p)
Apply this matrix to the point p and return the result (this will NOT change p). This method requires the matrix to be a 3x3, 3x4 or 4x4 matrix. If it is a 4x4 matrix the bottom row is assumed to be (0,0,0,1).


multiply

public Point multiply(Point p)

multiplyIn

public Point multiplyIn(Point p)
Apply this matrix to the point p and return the result (this will change p). This method requires the matrix to be a 3x3, 3x4 or 4x4 matrix. If it is a 4x4 matrix the bottom row is assumed to be (0,0,0,1).


multiply

public Vector multiply(Vector v)
Apply this matrix to the vector v and return the result (without changing v). This method requires the matrix to be a 3x3, 3x4 or 4x4 matrix. If it is a 4x4 matrix the bottom row is assumed to be (0,0,0,1).


multiplyThis

public Matrix multiplyThis(Matrix m)
Multiply this matrix to another matrix. This matrix is changed and then returned


multiply

public Matrix multiply(Matrix m)
Multiply this matrix to another matrix and return the result.


multiply_Strassen

public Matrix multiply_Strassen(Matrix B)

add

public Matrix add(Matrix m)
Add the components of two matrices. The result is stored in a new matrix and then returned.


addThis

public Matrix addThis(Matrix m)
Add the components of two matrices. The result is stored in this matrix and then returned.


subtract

public Matrix subtract(Matrix m)
Subtract the components of two matrices. The result is stored in a new matrix and then returned.


subtractThis

public Matrix subtractThis(Matrix m)
Subtract the components of two matrices. The result is stored in this matrix and then returned.


multiply

public Matrix multiply(double scalar)
Multiply the components of this matrix by a scalar. The result is stored in a new matrix which is returned.


multiplyThis

public Matrix multiplyThis(double scalar)
Multiply the components of this matrix by a scalar. Changes and then returns this


minor

public Matrix minor(int r,
                    int c)
Return the minor, i.e. the matrix that results from removing row r and column c from this matrix.


determinant

public double determinant()
Get the determinant of this matrix. Throws an error if the matrix is not square


isSquare

public boolean isSquare()

extend

public Matrix extend()
extends to the smallest square matrix by adding appropriate zero rows or columns


expand

public Matrix expand()
extends to the smallest power of 2 square matrix by adding appropriate zero rows and columns


invert

public Matrix invert()
Return the inverse of this matrix.


invertThis

public Matrix invertThis()
Invert this matrix (overwrites this and returns it).


reduce

public Matrix reduce()
Reduce this matrix to row canonical form (reduced row echelon form). A new object is returned.


reduceThis

public Matrix reduceThis()
Reduce this matrix to row canonical form (reduced row echelon form). This matrix is changed and returned.


orthonormalizeThis

public Matrix orthonormalizeThis()
Run Gram-Schmidt orthonormalization procedure. Assumes that the columns of this are linearly independent.

Returns:
this

equals

public boolean equals(Matrix m)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getEigenvalueDecomposition

public Matrix.EigenvalueDecomposition getEigenvalueDecomposition()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int dec)

toConsole

public void toConsole()

toConsole

public void toConsole(int dec)

clone

public Matrix clone()
Returns a clone of this matrix.

Overrides:
clone in class java.lang.Object

createRandomMatrix

public static Matrix createRandomMatrix(int n)

createIdentityMatrix

public static Matrix createIdentityMatrix(int n)

createColumnMatrix

public static Matrix3x3 createColumnMatrix(Vector v1,
                                           Vector v2,
                                           Vector v3)

create4x4ColumnMatrix

public static Matrix create4x4ColumnMatrix(Vector v1,
                                           Vector v2,
                                           Vector v3,
                                           Vector v4)

createRowMatrix

public static Matrix3x3 createRowMatrix(Vector v1,
                                        Vector v2,
                                        Vector v3)

createRotationMatrix

public static Matrix createRotationMatrix(double angle,
                                          Vector v)