jumbo.euclid
Class RealSquareMatrix

java.lang.Object
  |
  +--jumbo.euclid.Status
        |
        +--jumbo.euclid.RealMatrix
              |
              +--jumbo.euclid.RealSquareMatrix
Direct Known Subclasses:
Transform2, Transform3

public class RealSquareMatrix
extends RealMatrix

RealSquareMatrix - square matrix class

RealSquareMatrix represents a square m-x-m matrix. The basic matrix algebra for square matrices is represented here Check out the exciting member functions, which are supported by Exceptions where appropriate. (NB. No attempt has been made to provide numerical robustness and inversion, diagonalisation, etc are as you find them.)


Fields inherited from class jumbo.euclid.RealMatrix
cols, flmat, rows
 
Constructor Summary
RealSquareMatrix()
          This gives a default matrix, with cols = rows = 0.
RealSquareMatrix(double[][] matrix)
          form from a Java 2-D array (it holds row and column count)
RealSquareMatrix(int rows)
          This gives a null matrix
RealSquareMatrix(int rows, double f)
          initalises all elements in the array with a given double[]
RealSquareMatrix(int rows, double[] array)
          Formed by feeding in an existing array to a colsXcols matrix.
RealSquareMatrix(RealMatrix m)
          assign a RealMatrix - i.e.
RealSquareMatrix(RealMatrix m, int lowrow, int lowcol, int rows)
          submatrix of another matrix
RealSquareMatrix(RealSquareMatrix m)
           
 
Method Summary
 RealSquareMatrix copyLowerToUpper()
          copy lower triangle into upper triangle (i.e.
 RealSquareMatrix copyUpperToLower()
          copy upper triangle into lower triangle (i.e.
 double determinant()
          determinant - only goes up to order 3 at present :-(
static RealSquareMatrix diagonal(RealArray f)
          make diagonal matrix
 int diagonaliseAndReturnRank(RealArray eigenvalues, RealSquareMatrix eigenvectors, IllCondMatrixException illCond)
          diagonalisation - returns eigenvalues and vectors as MODIFIED arguments; this is NOT affected
 boolean equals(RealSquareMatrix r)
          are two matrices identical?
 RealSquareMatrix getInverse()
          inversion of matrix - creates NEW matrix
 boolean isImproperRotation()
          is matrix an improper rotation?
 boolean isLowerTriangular()
          is matrix lower triangular (including diagonal)?
 boolean isOrthogonal()
          is matrix orthogonal? (rowwise calculation)
 boolean isOrthonormal()
          is matrix unitary (orthonormal)? (synonym for isUnitary())
 boolean isSymmetric()
          is matrix symmetric?
 boolean isUnit()
          is it a unit matrix?
 boolean isUnitary()
           
 boolean isUpperTriangular()
          is matrix UpperTriangular?
 RealArray lowerTriangle()
          copy lower triangle into linear array; order: 0,0; 1,0; 1,1; 2,0 ..
static void main(java.lang.String[] args)
          tests RealSquareMatrix routines
 RealSquareMatrix multiply(RealSquareMatrix m)
          matrix multiplication - multiplies conformable matrices; result is this*m
 void orthogonalise()
          orthogonalise matrix (only works for 3x3 at present); MODIFIES matrix
 RealSquareMatrix orthonormalise()
          orthonormalise matrix (only works for 3x3 at present)
static RealSquareMatrix outerProduct(RealArray f)
          special types of matrix (Outerproduct, Diagonal, etc)
 RealSquareMatrix plus(RealSquareMatrix m)
          matrix addition - adds conformable matrices
 void shallowCopy(RealSquareMatrix m)
          shallowCopy an existing object
 RealSquareMatrix subtract(RealSquareMatrix m)
          matrix subtraction - subtracts conformable matrices
 double trace()
          trace
 void transpose()
          transpose - MODIFIES matrix
 
Methods inherited from class jumbo.euclid.RealMatrix
appendColumnData, appendColumnData, appendRowData, appendRowData, clearMatrix, clone, columnwiseDivide, deleteColumn, deleteColumns, deleteRow, deleteRows, elementAt, elementAt, elementsInRange, equals, euclideanColumnLength, euclideanColumnLengths, euclideanRowLength, euclideanRowLengths, extractColumnData, extractRowData, extractSubMatrixData, getCols, getMatrix, getMatrixAsArray, getRows, getTranspose, indexOfLargestElement, indexOfLargestElementInColumn, indexOfLargestElementInRow, indexOfSmallestElement, indexOfSmallestElementInColumn, indexOfSmallestElementInRow, insertColumnData, insertColumnData, insertColumns, insertRowData, insertRowData, insertRows, isSquare, largestElement, largestElementInColumn, largestElementInRow, multiply, multiply, multiplyBy, negative, normaliseByColumns, normaliseByRows, plus, reorderColumnsBy, reorderRowsBy, replaceColumnData, replaceColumnData, replaceColumnData, replaceRowData, replaceRowData, replaceRowData, replaceSubMatrixData, setAllElements, setElementAt, shallowCopy, smallestElement, smallestElementInColumn, smallestElementInRow, subtract, toString
 
Methods inherited from class jumbo.euclid.Status
NYI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RealSquareMatrix

public RealSquareMatrix()
This gives a default matrix, with cols = rows = 0.

RealSquareMatrix

public RealSquareMatrix(int rows)
This gives a null matrix

RealSquareMatrix

public RealSquareMatrix(int rows,
                        double[] array)
                 throws BadArgumentException
Formed by feeding in an existing array to a colsXcols matrix. THE COLUMN IS THE FASTEST MOVING INDEX, i.e. the matrix is filled as mat(0,0), mat(0,1) ... C-LIKE
Throws:
BadArgumentException - array size must be multiple of rows

RealSquareMatrix

public RealSquareMatrix(int rows,
                        double f)
initalises all elements in the array with a given double[]

RealSquareMatrix

public RealSquareMatrix(RealMatrix m,
                        int lowrow,
                        int lowcol,
                        int rows)
                 throws BadArgumentException
submatrix of another matrix
Throws:
BadArgumentException - lowrow, lowcol or rows are not consistent with size of m

RealSquareMatrix

public RealSquareMatrix(RealSquareMatrix m)

RealSquareMatrix

public RealSquareMatrix(RealMatrix m)
                 throws NonSquareException
assign a RealMatrix - i.e. NOT copied
Throws:
NonSquareException - m must be square (i.e. cols = rows)

RealSquareMatrix

public RealSquareMatrix(double[][] matrix)
                 throws MatrixShapeException
form from a Java 2-D array (it holds row and column count)
Throws:
MatrixShapeException - matrix is not square (might even not be rectangular!)
Method Detail

outerProduct

public static RealSquareMatrix outerProduct(RealArray f)
special types of matrix (Outerproduct, Diagonal, etc)

diagonal

public static RealSquareMatrix diagonal(RealArray f)
make diagonal matrix

shallowCopy

public void shallowCopy(RealSquareMatrix m)
                 throws UnequalMatricesException
shallowCopy an existing object
Throws:
UnequalMatricesException - m must have the same number of rows and cols as this

equals

public boolean equals(RealSquareMatrix r)
               throws UnequalMatricesException
are two matrices identical?
Throws:
UnequalMatricesException - m must have the same number of rows and cols as this

plus

public RealSquareMatrix plus(RealSquareMatrix m)
                      throws MatrixShapeException
matrix addition - adds conformable matrices
Throws:
MatrixShapeException - m must have the same number of rows and cols as this

subtract

public RealSquareMatrix subtract(RealSquareMatrix m)
                          throws MatrixShapeException
matrix subtraction - subtracts conformable matrices
Throws:
MatrixShapeException - m must have the same number of rows and cols as this

multiply

public RealSquareMatrix multiply(RealSquareMatrix m)
                          throws MatrixShapeException
matrix multiplication - multiplies conformable matrices; result is this*m
Throws:
MatrixShapeException - m must have the same number of rows as this has cols

determinant

public double determinant()
                   throws UnimplementedException
determinant - only goes up to order 3 at present :-(
Throws:
UnimplementedException - I have only written this for this.rows up to 3. If anyone can find a determinant routine, this will disappear ... -(

trace

public double trace()
trace

isUnit

public boolean isUnit()
is it a unit matrix?

isSymmetric

public boolean isSymmetric()
is matrix symmetric?

orthonormalise

public RealSquareMatrix orthonormalise()
                                throws UnimplementedException
orthonormalise matrix (only works for 3x3 at present)
Throws:
UnimplementedException - I have only written this for this.rows up to 3. If anyone can find a routine, this will disappear ... -(

isOrthonormal

public boolean isOrthonormal()
is matrix unitary (orthonormal)? (synonym for isUnitary())

isUpperTriangular

public boolean isUpperTriangular()
is matrix UpperTriangular?

isLowerTriangular

public boolean isLowerTriangular()
is matrix lower triangular (including diagonal)?

isOrthogonal

public boolean isOrthogonal()
is matrix orthogonal? (rowwise calculation)
Overrides:
isOrthogonal in class RealMatrix

isImproperRotation

public boolean isImproperRotation()
is matrix an improper rotation?

isUnitary

public boolean isUnitary()

copyUpperToLower

public RealSquareMatrix copyUpperToLower()
copy upper triangle into lower triangle (i.e. make symmetric)

copyLowerToUpper

public RealSquareMatrix copyLowerToUpper()
copy lower triangle into upper triangle (i.e. make symmetric)

lowerTriangle

public RealArray lowerTriangle()
copy lower triangle into linear array; order: 0,0; 1,0; 1,1; 2,0 ..

transpose

public void transpose()
transpose - MODIFIES matrix

diagonaliseAndReturnRank

public int diagonaliseAndReturnRank(RealArray eigenvalues,
                                    RealSquareMatrix eigenvectors,
                                    IllCondMatrixException illCond)
                             throws ArrayTooSmallException
diagonalisation - returns eigenvalues and vectors as MODIFIED arguments; this is NOT affected

Note that IllCondMatrixException is RETURNED and not thrown

Throws:
ArrayTooSmallException - must have at least order 2

orthogonalise

public void orthogonalise()
                   throws UnimplementedException
orthogonalise matrix (only works for 3x3 at present); MODIFIES matrix
Throws:
UnimplementedException - I have only written this for this.rows up to 3. If anyone can find a routine, this will disappear ... -(

getInverse

public RealSquareMatrix getInverse()
                            throws SingMatrixException
inversion of matrix - creates NEW matrix
Throws:
SingMatrixException - singular matrix (or worse!)

main

public static void main(java.lang.String[] args)
tests RealSquareMatrix routines