Class pmr.euclid.RealMatrix
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class pmr.euclid.RealMatrix

java.lang.Object
   |
   +----pmr.euclid.Status
           |
           +----pmr.euclid.RealMatrix

public class RealMatrix
extends Status

RealMatrix - rectangular real number matrix class

RealMatrix represents a rectangular m-x-n matrix. The basic matrix algebra for non-square matrices is represented here and this class is also a base for square matrices.

Read the signature of each member function carefully as some MODIFY the object and some CREATE A NEW ONE. Among the reasons for this is that subclassing (e.g to RealSquareMatrix) is easier with one of these forms in certain cases. Note that if you modify an object, then all references to it will refer to the changed object

Author:
(C) P. Murray-Rust, 1996

Variable Index

 o cols
number of columns
 o flmat
the matrix
 o rows
number of rows

Constructor Index

 o RealMatrix()
Default matrix, with cols = rows = 0
 o RealMatrix(double[][])
COPY from an existing matrix - check that it is rectangular
 o RealMatrix(int, int)
A rows*cols matrix set to 0.0 (rows or cols < 0 defaults to 0)
 o RealMatrix(int, int, double)
initalises all elements in the array with a given double[]
 o RealMatrix(int, int, double[])
Formed by feeding in an existing 1-D array to a rowsXcols matrix.
 o RealMatrix(IntMatrix)
from a IntMatrix
 o RealMatrix(RealMatrix)
copy constructor - COPIES the other matrix
 o RealMatrix(RealMatrix, int, int, int, int)
submatrix of another matrix; fails if lowrow > hirow, lowrow < 0, etc.

Method Index

 o appendColumnData(RealArray)
append data to matrix columnwise
 o appendColumnData(RealMatrix)
append data to matrix columnwise
 o appendRowData(RealArray)
append data to matrix rowwise
 o appendRowData(RealMatrix)
append data to matrix rowwise
 o clearMatrix()
clear matrix
 o clone(RealMatrix)
 o columnwiseDivide(RealArray)
divide each column of a matrix by a vector of scalars (i.e.
 o deleteColumn(int)
delete column from matrix and close up
 o deleteColumns(int, int)
delete 2 or more adjacent columns (inclusive) from matrix and close up
 o deleteRow(int)
delete row from matrix and close up
 o deleteRows(int, int)
delete 2 or more adjacent rows (inclusive) from matrix and close up; if (high > rows-1 high -> rows-1; or low < 0, low -> 0
 o elementAt(int, int)
extracts a given element from the matrix
 o elementAt(Int2)
extracts a given element from the matrix
 o elementsInRange(RealRange)
produce a mask of those elements which fall in a range (1) else (0)
 o equals(RealMatrix)
are two matrices equal in all elements?
 o euclideanColumnLength(int)
get Euclidean length of column
 o euclideanColumnLengths()
get array of Euclidean column lengths
 o euclideanRowLength(int)
get Euclidean length of row
 o euclideanRowLengths()
get array of Euclidean row lengths
 o extractColumnData(int)
get column data from matrix
 o extractRowData(int)
get row data from matrix
 o extractSubMatrixData(int, int, int, int)
extract a RealMatrix submatrix from a RealMatrix
 o getCols()
get number of columns
 o getMatrix()
 o getMatrixAsArray()
get matrix as double[] (in C order: m(0,0), m(0,1) ...)
 o getRows()
get number of rows
 o getTranspose()
transpose matrix - creates new Matrix
 o indexOfLargestElement()
get index of largest element
 o indexOfLargestElementInColumn(int)
get index of largest element in column
 o indexOfLargestElementInRow(int)
get index of largest element in row (or -1 if default matrix)
 o indexOfSmallestElement()
get index of smallest element
 o indexOfSmallestElementInColumn(int)
get index of smallest elem in column
 o indexOfSmallestElementInRow(int)
get index of smallest element in row
 o insertColumnData(int, RealArray)
add data as column or column block into matrix and expand
 o insertColumnData(int, RealMatrix)
add data as column or column block into matrix and expand
 o insertColumns(int, int)
insert a hole into the matric and expand
 o insertRowData(int, RealArray)
insert row of data into matrix and expand
 o insertRowData(int, RealMatrix)
insert 2 or more adjacent rows of data into matrix and expand
 o insertRows(int, int)
make space for new rows in matrix and expand
 o isOrthogonal()
is matrix Orthogonal (row-wise)? i.e.
 o isSquare()
is the matrix square?
 o largestElement()
get largest element
 o largestElementInColumn(int)
get largest element in a column
 o largestElementInRow(int)
get largest element in a row
 o main(String[])
tests RealMatrix routines = new RealMatrix
 o multiply(RealArray)
matrix multiplication of a COLUMN vector
 o multiply(RealMatrix)
matrix multiplication - multiplies conformable matrices to give NEW matrix result = 'this' * m; (order matters)
 o multiplyBy(double)
matrix multiplication by a scalar - MODIFIES matrix
 o negative()
unary minus - negate all elements of matrix; MODIFIES matrix
 o normaliseByColumns()
normalise matrix columns to length of 1.0
 o normaliseByRows()
normalise matrix rows to length of 1.0
 o plus(RealMatrix)
matrix addition - adds conformable matrices giving NEW matrix
 o reorderColumnsBy(IntSet)
reorder the columns of a matrix.
 o reorderRowsBy(IntSet)
reorder the rows of a matrix.
 o replaceColumnData(int, double[])
and from double[]
 o replaceColumnData(int, RealArray)
replace data in a single column - return false if impossible
 o replaceColumnData(int, RealMatrix)
replace data in a block of columns
 o replaceRowData(int, double[])
and using a double[]
 o replaceRowData(int, RealArray)
overwrite existing row of data
 o replaceRowData(int, RealMatrix)
overwrite existing block of rows; if too big, copying is truncated
 o replaceSubMatrixData(int, int, RealMatrix)
replaces the data starting at (low_row, low_col) and extending by the dimensions for the matrix m
 o setAllElements(double)
initialise matrix to given double
 o setElementAt(int, int, double)
inserts a given element to the matrix - MODIFIES matrix
 o shallowCopy(RealMatrix)
shallowCopy
 o smallestElement()
get smallest element
 o smallestElementInColumn(int)
get smallest element in a column
 o smallestElementInRow(int)
get smallest element in a row
 o subtract(RealMatrix)
matrix subtraction - subtracts conformable matrices giving NEW matrix
 o toString()
output matrix - very crude...

Variables

 o rows
  protected int rows
number of rows
 o cols
  protected int cols
number of columns
 o flmat
  protected double flmat[][]
the matrix

Constructors

 o RealMatrix
  public RealMatrix()
Default matrix, with cols = rows = 0
 o RealMatrix
  public RealMatrix(int r,
                    int c)
A rows*cols matrix set to 0.0 (rows or cols < 0 defaults to 0)
 o RealMatrix
  public RealMatrix(int rows,
                    int cols,
                    double array[]) throws InvalidArgumentException
Formed by feeding in an existing 1-D array to a rowsXcols matrix. THE COLUMN IS THE FASTEST MOVING INDEX, i.e. the matrix is filled as flmat(0,0), flmat(0,1) ... C-LIKE. COPIES the array
Throws: InvalidArgumentException
size of array is not rows*cols
 o RealMatrix
  public RealMatrix(int r,
                    int c,
                    double f)
initalises all elements in the array with a given double[]
 o RealMatrix
  public RealMatrix(RealMatrix m,
                    int lowrow,
                    int hirow,
                    int lowcol,
                    int hicol) throws InvalidArgumentException
submatrix of another matrix; fails if lowrow > hirow, lowrow < 0, etc. COPIES the parts of m
Throws: InvalidArgumentException
impossible value of hirow, hicol, lowrow, lowcol
 o RealMatrix
  public RealMatrix(RealMatrix m)
copy constructor - COPIES the other matrix
 o RealMatrix
  public RealMatrix(IntMatrix m)
from a IntMatrix
 o RealMatrix
  public RealMatrix(double m[][]) throws NonRectangularMatrixException
COPY from an existing matrix - check that it is rectangular
Throws: NonRectangularMatrixException
m has rows of different lengths

Methods

 o shallowCopy
  public void shallowCopy(RealMatrix m)
shallowCopy
 o clone
  public RealMatrix clone(RealMatrix m)
 o getRows
  public int getRows()
get number of rows
 o getCols
  public int getCols()
get number of columns
 o getMatrix
  public double[][] getMatrix()
 o getMatrixAsArray
  public double[] getMatrixAsArray()
get matrix as double[] (in C order: m(0,0), m(0,1) ...)
 o equals
  public boolean equals(RealMatrix m) throws UnconformableMatricesException
are two matrices equal in all elements?
Throws: UnconformableMatricesException
m and this are different sizes
 o plus
  public RealMatrix plus(RealMatrix m2) throws UnconformableMatricesException
matrix addition - adds conformable matrices giving NEW matrix
Throws: UnconformableMatricesException
m and this are different sizes
 o subtract
  public RealMatrix subtract(RealMatrix m2) throws UnconformableMatricesException
matrix subtraction - subtracts conformable matrices giving NEW matrix
Throws: UnconformableMatricesException
m and this are different sizes
 o negative
  public void negative()
unary minus - negate all elements of matrix; MODIFIES matrix
 o multiply
  public RealMatrix multiply(RealMatrix m) throws UnconformableMatricesException
matrix multiplication - multiplies conformable matrices to give NEW matrix result = 'this' * m; (order matters)
Throws: UnconformableMatricesException
m and this are different sizes
 o multiplyBy
  public void multiplyBy(double f)
matrix multiplication by a scalar - MODIFIES matrix
 o multiply
  public RealArray multiply(RealArray f) throws UnconformableMatricesException
matrix multiplication of a COLUMN vector
Throws: UnconformableMatricesException
f.size() differs from cols
 o columnwiseDivide
  public void columnwiseDivide(RealArray f) throws UnconformableMatricesException
divide each column of a matrix by a vector of scalars (i.e. mat[i][j] = mat[i][j] / vect[i] - MODIFIES matrix
Throws: UnconformableMatricesException
f.size() and rows differ
 o elementAt
  public double elementAt(int row,
                          int col)
extracts a given element from the matrix
 o elementAt
  public double elementAt(Int2 rowcol)
extracts a given element from the matrix
 o setElementAt
  public void setElementAt(int row,
                           int col,
                           double f)
inserts a given element to the matrix - MODIFIES matrix
 o largestElement
  public double largestElement()
get largest element
 o indexOfLargestElement
  public Int2 indexOfLargestElement()
get index of largest element
 o largestElementInColumn
  public double largestElementInColumn(int jcol)
get largest element in a column
 o indexOfLargestElementInColumn
  public int indexOfLargestElementInColumn(int jcol)
get index of largest element in column
 o largestElementInRow
  public double largestElementInRow(int irow)
get largest element in a row
 o indexOfLargestElementInRow
  public int indexOfLargestElementInRow(int irow)
get index of largest element in row (or -1 if default matrix)
 o smallestElement
  public double smallestElement()
get smallest element
 o indexOfSmallestElement
  public Int2 indexOfSmallestElement()
get index of smallest element
 o smallestElementInColumn
  public double smallestElementInColumn(int jcol)
get smallest element in a column
 o indexOfSmallestElementInColumn
  public int indexOfSmallestElementInColumn(int jcol)
get index of smallest elem in column
 o smallestElementInRow
  public double smallestElementInRow(int irow)
get smallest element in a row
 o indexOfSmallestElementInRow
  public int indexOfSmallestElementInRow(int irow)
get index of smallest element in row
 o isOrthogonal
  public boolean isOrthogonal()
is matrix Orthogonal (row-wise)? i.e. row(i) * row(j) = 0 if i != j.
 o euclideanRowLength
  public double euclideanRowLength(int i)
get Euclidean length of row
 o euclideanRowLengths
  public RealArray euclideanRowLengths()
get array of Euclidean row lengths
 o euclideanColumnLength
  public double euclideanColumnLength(int i)
get Euclidean length of column
 o euclideanColumnLengths
  public RealArray euclideanColumnLengths()
get array of Euclidean column lengths
 o extractColumnData
  public RealArray extractColumnData(int col)
get column data from matrix
 o extractRowData
  public RealArray extractRowData(int row)
get row data from matrix
 o clearMatrix
  public void clearMatrix()
clear matrix
 o setAllElements
  public void setAllElements(double f)
initialise matrix to given double
 o normaliseByRows
  public void normaliseByRows()
normalise matrix rows to length of 1.0
 o normaliseByColumns
  public void normaliseByColumns()
normalise matrix columns to length of 1.0
 o getTranspose
  public RealMatrix getTranspose()
transpose matrix - creates new Matrix
 o isSquare
  public boolean isSquare()
is the matrix square?
 o deleteColumn
  public void deleteColumn(int col)
delete column from matrix and close up
 o deleteColumns
  public void deleteColumns(int low,
                            int high)
delete 2 or more adjacent columns (inclusive) from matrix and close up
 o deleteRow
  public void deleteRow(int row)
delete row from matrix and close up
 o deleteRows
  public void deleteRows(int low,
                         int high)
delete 2 or more adjacent rows (inclusive) from matrix and close up; if (high > rows-1 high -> rows-1; or low < 0, low -> 0
 o replaceColumnData
  public boolean replaceColumnData(int column,
                                   RealArray f)
replace data in a single column - return false if impossible
 o replaceColumnData
  public void replaceColumnData(int starting_col,
                                double f[])
and from double[]
 o replaceColumnData
  public void replaceColumnData(int start_column,
                                RealMatrix m)
replace data in a block of columns
 o insertColumns
  public void insertColumns(int after_col,
                            int delta_cols)
insert a hole into the matric and expand
 o insertColumnData
  public void insertColumnData(int after_col,
                               RealArray f)
add data as column or column block into matrix and expand
 o insertColumnData
  public void insertColumnData(int after_col,
                               RealMatrix m)
add data as column or column block into matrix and expand
 o insertRows
  public void insertRows(int after_row,
                         int delta_rows)
make space for new rows in matrix and expand
 o replaceRowData
  public void replaceRowData(int row,
                             RealArray f) throws UnconformableMatricesException
overwrite existing row of data
Throws: UnconformableMatricesException
f.size() and cols differ
 o replaceRowData
  public void replaceRowData(int row,
                             double f[]) throws UnconformableMatricesException
and using a double[]
Throws: UnconformableMatricesException
f.length and cols differ
 o replaceRowData
  public void replaceRowData(int after_row,
                             RealMatrix m) throws UnconformableMatricesException
overwrite existing block of rows; if too big, copying is truncated
Throws: UnconformableMatricesException
m.rows and this.rows differ
 o insertRowData
  public void insertRowData(int after_row,
                            RealMatrix m) throws UnconformableMatricesException
insert 2 or more adjacent rows of data into matrix and expand
Throws: UnconformableMatricesException
m.cols and this.colsdiffer
 o insertRowData
  public void insertRowData(int after_row,
                            RealArray f) throws UnconformableMatricesException
insert row of data into matrix and expand
Throws: UnconformableMatricesException
f.size() and this.cols differ
 o appendColumnData
  public void appendColumnData(RealArray f) throws UnconformableMatricesException
append data to matrix columnwise
Throws: UnconformableMatricesException
f.size() and this.rows differ
 o appendColumnData
  public void appendColumnData(RealMatrix m) throws UnconformableMatricesException
append data to matrix columnwise
Throws: UnconformableMatricesException
m.rows and this.rows differ
 o appendRowData
  public void appendRowData(RealArray f) throws UnconformableMatricesException
append data to matrix rowwise
Throws: UnconformableMatricesException
m.cols and this.cols differ
 o appendRowData
  public void appendRowData(RealMatrix m) throws UnconformableMatricesException
append data to matrix rowwise
Throws: UnconformableMatricesException
m.cols and this.cols differ
 o replaceSubMatrixData
  public void replaceSubMatrixData(int low_row,
                                   int low_col,
                                   RealMatrix m)
replaces the data starting at (low_row, low_col) and extending by the dimensions for the matrix m
 o reorderColumnsBy
  public RealMatrix reorderColumnsBy(IntSet is) throws UnconformableMatricesException, ArrayIndexOutOfBoundsException
reorder the columns of a matrix.
Throws: UnconformableMatricesException
is.size() and this.cols differ
Throws: ArrayIndexOutOfBoundsException
an element of is >= this.cols
 o reorderRowsBy
  public RealMatrix reorderRowsBy(IntSet is) throws UnconformableMatricesException, ArrayIndexOutOfBoundsException
reorder the rows of a matrix. Deleting rows is allowed
Throws: UnconformableMatricesException
is.size() and this.rows differ
Throws: ArrayIndexOutOfBoundsException
an element of is >= this.rows
 o extractSubMatrixData
  public RealMatrix extractSubMatrixData(int low_row,
                                         int high_row,
                                         int low_col,
                                         int high_col) throws InvalidArgumentException
extract a RealMatrix submatrix from a RealMatrix
Throws: InvalidArgumentException
low/high_row/col are outside range of this
 o elementsInRange
  public IntMatrix elementsInRange(RealRange r)
produce a mask of those elements which fall in a range (1) else (0)
 o toString
  public String toString()
output matrix - very crude...
Overrides:
toString in class Object
 o main
  public static void main(String args[])
tests RealMatrix routines = new RealMatrix

All Packages  Class Hierarchy  This Package  Previous  Next  Index