public class RealMatrix extends Object implements EuclidConstants
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
| Modifier and Type | Field and Description |
|---|---|
protected int |
cols
number of columns
|
protected double[][] |
flmat
the matrix
|
protected int |
rows
number of rows
|
C_AMP, C_APOS, C_ATSIGN, C_BACKSLASH, C_BACKSPACE, C_CARET, C_COLON, C_COMMA, C_DEL, C_DOLLAR, C_EQUALS, C_FORMFEED, C_HASH, C_LANGLE, C_LBRAK, C_LCURLY, C_LSQUARE, C_MINUS, C_NBSP, C_NEWLINE, C_NL, C_PERCENT, C_PERIOD, C_PIPE, C_PLUS, C_POUND, C_QUERY, C_QUOT, C_RANGLE, C_RBRAK, C_RCURLY, C_RETURN, C_RSQUARE, C_SEMICOLON, C_SHRIEK, C_SLASH, C_SPACE, C_STAR, C_TAB, C_TILDE, C_UNDER, EPS, F_S, NONWHITEPUNC, NONWHITEPUNC0, NONWHITEPUNC0REGEX, ONE_THIRD, PUNC, S_AMP, S_APOS, S_ATSIGN, S_BACKSLASH, S_CARET, S_COLON, S_COMMA, S_DOLLAR, S_EMPTY, S_EQUALS, S_FORMFEED, S_HASH, S_LANGLE, S_LBRAK, S_LCURLY, S_LSQUARE, S_MINUS, S_NEWLINE, S_NL, S_PERCENT, S_PERIOD, S_PIPE, S_PLUS, S_POUND, S_QUERY, S_QUOT, S_RANGLE, S_RBRAK, S_RCURLY, S_RETURN, S_RSQUARE, S_SEMICOLON, S_SHRIEK, S_SLASH, S_SPACE, S_STAR, S_TAB, S_TILDE, S_UNDER, S_WHITEREGEX, TWO_THIRDS, U_S, WHITESPACE| Constructor and Description |
|---|
RealMatrix()
construct default matrix.
|
RealMatrix(double[][] m)
create from a java matrix.
|
RealMatrix(int r,
int c)
Create matrix with given rows and columns.
|
RealMatrix(int r,
int c,
double f)
creates matrix with initialised values.
|
RealMatrix(int rows,
int cols,
double[] array)
Create from 1-D array.
|
RealMatrix(IntMatrix m)
construct from a IntMatrix.
|
RealMatrix(RealMatrix m)
copy constructor.
|
RealMatrix(RealMatrix m,
int lowrow,
int hirow,
int lowcol,
int hicol)
create from submatrix of another matrix.
|
| Modifier and Type | Method and Description |
|---|---|
void |
appendColumnData(RealArray f)
append data to matrix columnwise.
|
void |
appendColumnData(RealMatrix m)
append data to matrix columnwise.
|
void |
appendRowData(RealArray f)
append data to matrix rowwise.
|
void |
appendRowData(RealMatrix m)
append data to matrix rowwise.
|
protected boolean |
checkNonEmptyMatrix() |
void |
clearMatrix()
clear matrix.
|
void |
columnwiseDivide(RealArray f)
divide each column of a matrix by a vector of scalars (that is mat[i][j] =
mat[i][j] / vect[i] - MODIFIES matrix
|
RealMatrix |
createMatrixWithOriginShifted(double deltax,
double deltay) |
void |
deleteColumn(int col)
delete column from matrix and close up.
|
void |
deleteColumns(int low,
int high)
delete 2 or more adjacent columns (inclusive) from matrix and close up.
|
void |
deleteRow(int row)
delete row from matrix and close up.
|
void |
deleteRows(int low,
int high)
delete 2 or more adjacent rows (inclusive) from matrix and close up.
|
double |
elementAt(Int2 rowcol)
extracts a given element.
|
double |
elementAt(int row,
int col)
extracts a given element.
|
IntMatrix |
elementsInRange(RealRange r)
produce a mask of those elements which fall in a range.
|
double |
euclideanColumnLength(int jcol)
get Euclidean length of column.
|
RealArray |
euclideanColumnLengths()
get array of Euclidean column lengths
|
double |
euclideanRowLength(int i)
get Euclidean length of row.
|
RealArray |
euclideanRowLengths()
get array of Euclidean row lengths.
|
RealArray |
extractColumnData(int col)
get column data from matrix.
|
Real2Array |
extractColumns(int col1,
int col2)
make an Real2_Array from columns.
|
RealArray |
extractRowData(int row)
get row data from matrix.
|
Real2Array |
extractRows(int row1,
int row2)
make an Real2_Array from rows.
|
RealMatrix |
extractSubMatrixData(int low_row,
int high_row,
int low_col,
int high_col)
extract a RealMatrix submatrix from a RealMatrix
|
RealMatrix |
format(int places)
round to decimal places.
|
int |
getCols()
get number of columns.
|
DecimalFormat |
getFormat()
get output format.
|
IntMatrix |
getIntMatrix()
constructs an IntMatrix.
|
double[][] |
getMatrix()
get matrix as java matrix.
|
double[] |
getMatrixAsArray()
get matrix as array.
|
int |
getRows()
get number of rows.
|
RealMatrix |
getTranspose()
transpose matrix - creates new Matrix
|
Int2 |
indexOfLargestElement()
get index of largest element.
|
int |
indexOfLargestElementInColumn(int jcol)
get index of largest element in column.
|
int |
indexOfLargestElementInRow(int irow)
get index of largest element in row.
|
Int2 |
indexOfSmallestElement()
get index of smallest element.
|
int |
indexOfSmallestElementInColumn(int jcol)
get index of smallest element in column.
|
int |
indexOfSmallestElementInRow(int irow)
get index of smallest element in row.
|
void |
insertColumnData(int after_col,
RealArray f)
add data as column or column block into matrix and expand.
|
void |
insertColumnData(int afterCol,
RealMatrix m)
add data as column or column block into matrix and expand.
|
void |
insertRowData(int after_row,
RealArray f)
insert row of data into matrix and expand.
|
void |
insertRowData(int afterRow,
RealMatrix m)
insert 2 or more adjacent rows of data into matrix and expand
|
void |
insertRows(int after_row,
int delta_rows)
make space for new rows in matrix and expand.
|
boolean |
isEqualTo(RealMatrix m)
tests matrices for equality.
|
boolean |
isOrthogonal()
is matrix Orthogonal row-wise.
|
boolean |
isSquare()
is the matrix square
|
boolean |
isZero(double eps)
are all elements of matrix zero?
|
double |
largestElement()
get value of largest element.
|
double |
largestElementInColumn(int jcol)
get value of largest element in a column
|
double |
largestElementInRow(int irow)
get value of largest element in a row.
|
void |
makeSpaceForNewColumns(int after_col,
int delta_cols)
insert a hole into the matrix and expand.
|
RealArray |
multiply(RealArray f)
matrix multiplication of a COLUMN vector.
|
RealMatrix |
multiply(RealMatrix m)
matrix multiplication.
|
void |
multiplyBy(double f)
matrix multiplication by a scalar.
|
void |
multiplyEquals(RealMatrix m)
matrix multiplication.
|
void |
negative()
unary minus.
|
void |
normaliseByColumns()
normalise matrix columns to length of unity
|
void |
normaliseByRows()
normalise matrix rows to length of unity
|
RealMatrix |
plus(RealMatrix m2)
matrix addition.
|
RealMatrix |
reorderColumnsBy(IntSet is)
reorder the columns of a matrix.
|
RealMatrix |
reorderRowsBy(IntSet is)
reorder the rows of a matrix Deleting rows is allowed
|
void |
replaceColumnData(int starting_col,
double[] f)
replace data in a single column.
|
void |
replaceColumnData(int column,
RealArray f)
replace data in a single column.
|
void |
replaceColumnData(int start_column,
RealMatrix m)
replace data in a block of columns.
|
void |
replaceRowData(int row,
double[] f)
overwrite existing row of data.
|
void |
replaceRowData(int row,
RealArray f)
overwrite existing row of data.
|
void |
replaceRowData(int afterRow,
RealMatrix m)
overwrite existing block of rows; if too big, copying is truncated
|
void |
replaceSubMatrixData(int low_row,
int low_col,
RealMatrix m)
replaces the data in a submatrix.
|
RealMatrix |
scaleAndInterpolate(int newRows,
int newCols) |
void |
setAllElements(double f)
initialise matrix to given double.
|
void |
setElementAt(int row,
int col,
double f)
sets a given element MODIFIES matrix
|
void |
setFormat(DecimalFormat f)
set output format.
|
void |
shallowCopy(RealMatrix m)
shallow copy constructor.
|
double |
smallestElement()
get value of smallest element.
|
double |
smallestElementInColumn(int jcol)
get smallest element in a column.
|
double |
smallestElementInRow(int irow)
get smallest element in a row.
|
RealMatrix |
subtract(RealMatrix m2)
matrix subtraction.
|
String |
toString()
output matrix - very crude
|
void |
translateByColumn(double[] d)
subtract value from each colum.
|
void |
writeXML(Writer w)
output xml as a CML matrix.
|
protected int rows
protected int cols
protected double[][] flmat
public RealMatrix()
public RealMatrix(int r,
int c)
r - number of rowsc - number of columnspublic RealMatrix(int rows,
int cols,
double[] array)
throws EuclidRuntimeException
rows - cols - array - EuclidRuntimeException - size of array is not rows*colspublic RealMatrix(int r,
int c,
double f)
r - rowsc - columnsf - value to initialize withpublic RealMatrix(RealMatrix m, int lowrow, int hirow, int lowcol, int hicol) throws EuclidRuntimeException
mm - the matrix to slicelowcol - lowest column indexhicol - highest column indexlowrow - lowest row indexhirow - highest row indexEuclidRuntimeException - impossible value of hirow, hicol, lowrow, lowcolpublic RealMatrix(RealMatrix m)
m - matrix to copypublic RealMatrix(IntMatrix m)
m - matrix to copy (this(i,j) = m(i,j))public RealMatrix(double[][] m)
throws EuclidRuntimeException
m - natrix to copy fromEuclidRuntimeException - m has rows of different lengthspublic void shallowCopy(RealMatrix m)
m - matrix to copypublic IntMatrix getIntMatrix()
public void setFormat(DecimalFormat f)
f - the formatpublic DecimalFormat getFormat()
public int getRows()
public int getCols()
public double[][] getMatrix()
public double[] getMatrixAsArray()
public boolean isEqualTo(RealMatrix m)
m - public RealMatrix plus(RealMatrix m2) throws EuclidRuntimeException
m2 - EuclidRuntimeException - m and this are different sizespublic RealMatrix subtract(RealMatrix m2) throws EuclidRuntimeException
m2 - EuclidRuntimeException - m and this are different sizespublic void negative()
public RealMatrix multiply(RealMatrix m) throws EuclidRuntimeException
m - EuclidRuntimeException - m and this are different sizespublic void multiplyBy(double f)
f - scalarpublic void multiplyEquals(RealMatrix m) throws EuclidRuntimeException
m - matrix to multiply byEuclidRuntimeException - m and this are different sizespublic void translateByColumn(double[] d)
throws EuclidRuntimeException
d - array of doubles to subtractEuclidRuntimeExceptionpublic RealArray multiply(RealArray f) throws EuclidRuntimeException
f - vector to multiplyEuclidRuntimeException - f.size() differs from colspublic void columnwiseDivide(RealArray f) throws EuclidRuntimeException
f - array to divide byEuclidRuntimeException - f.size() and rows differpublic double elementAt(int row,
int col)
throws EuclidRuntimeException
row - col - EuclidRuntimeException - bad value of row or columnpublic double elementAt(Int2 rowcol) throws EuclidRuntimeException
rowcol - represents row,colEuclidRuntimeExceptionpublic void setElementAt(int row,
int col,
double f)
throws EuclidRuntimeException
row - col - f - EuclidRuntimeExceptionpublic double largestElement()
public Int2 indexOfLargestElement()
public double largestElementInColumn(int jcol)
throws EuclidRuntimeException
jcol - EuclidRuntimeExceptionpublic int indexOfLargestElementInColumn(int jcol)
throws EuclidRuntimeException
jcol - indexEuclidRuntimeException - bad value of jcolpublic int indexOfLargestElementInRow(int irow)
throws EuclidRuntimeException
irow - indexEuclidRuntimeException - bad value of irowpublic int indexOfSmallestElementInColumn(int jcol)
throws EuclidRuntimeException
jcol - indexEuclidRuntimeException - bad value of jcolprotected boolean checkNonEmptyMatrix()
public double largestElementInRow(int irow)
throws EuclidRuntimeException
irow - EuclidRuntimeExceptionpublic int indexOfSmallestElementInRow(int irow)
throws EuclidRuntimeException
irow - indexEuclidRuntimeException - bad value of irowpublic double smallestElement()
throws EuclidRuntimeException
EuclidRuntimeExceptionpublic Int2 indexOfSmallestElement()
public double smallestElementInColumn(int jcol)
throws EuclidRuntimeException
jcol - EuclidRuntimeException - bad value of jcolpublic double smallestElementInRow(int irow)
throws EuclidRuntimeException
irow - EuclidRuntimeException - bad value of irowpublic boolean isOrthogonal()
public double euclideanRowLength(int i)
throws EuclidRuntimeException
i - the rowEuclidRuntimeException - bad row numberpublic RealArray euclideanRowLengths()
public double euclideanColumnLength(int jcol)
throws EuclidRuntimeException
jcol - the columnEuclidRuntimeExceptionpublic RealArray euclideanColumnLengths()
public RealArray extractColumnData(int col) throws EuclidRuntimeException
col - the columnEuclidRuntimeException - bad indexpublic RealArray extractRowData(int row) throws EuclidRuntimeException
row - the columnEuclidRuntimeException - bad indexpublic void clearMatrix()
public void setAllElements(double f)
f - public void normaliseByRows()
public void normaliseByColumns()
public RealMatrix getTranspose()
public boolean isSquare()
public boolean isZero(double eps)
eps - tolerancepublic void deleteColumn(int col)
col - the columnpublic void deleteColumns(int low,
int high)
low - start columnhigh - end columnpublic void deleteRow(int row)
row - public void deleteRows(int low,
int high)
low - start rowhigh - end rowpublic void replaceColumnData(int column,
RealArray f)
throws EuclidRuntimeException
column - f - data must be of length rowsEuclidRuntimeExceptionpublic void replaceColumnData(int starting_col,
double[] f)
throws EuclidRuntimeException
starting_col - f - data must be of length rowsEuclidRuntimeExceptionpublic void replaceColumnData(int start_column,
RealMatrix m)
throws EuclidRuntimeException
start_column - (gets overwritten)m - must have same row count and fit into gapEuclidRuntimeExceptionpublic void makeSpaceForNewColumns(int after_col,
int delta_cols)
after_col - delta_cols - public void insertColumnData(int after_col,
RealArray f)
throws EuclidRuntimeException
after_col - -1 to cols-1f - EuclidRuntimeExceptionpublic void insertColumnData(int afterCol,
RealMatrix m)
throws EuclidRuntimeException
afterCol - -1 to cols-1m - EuclidRuntimeExceptionpublic void insertRows(int after_row,
int delta_rows)
after_row - -1 to rows-1delta_rows - size of spacepublic void replaceRowData(int row,
RealArray f)
throws EuclidRuntimeException
row - to replacef - row to useEuclidRuntimeException - f.size() and cols differpublic void replaceRowData(int row,
double[] f)
throws EuclidRuntimeException
row - to replacef - row to useEuclidRuntimeException - f.length and cols differpublic void replaceRowData(int afterRow,
RealMatrix m)
throws EuclidRuntimeException
afterRow - from -1 to rows-1m - data to replace withEuclidRuntimeException - m.rows and this.rows differpublic void insertRowData(int afterRow,
RealMatrix m)
throws EuclidRuntimeException
afterRow - from -1 to rows-1m - data to insertEuclidRuntimeException - m.cols and this.colsdifferpublic void insertRowData(int after_row,
RealArray f)
throws EuclidRuntimeException
after_row - from -1 to rows-1f - data to insertEuclidRuntimeException - f.size() and this.cols differpublic void appendColumnData(RealArray f) throws EuclidRuntimeException
f - data to appendEuclidRuntimeException - f.size() and this.rows differpublic void appendColumnData(RealMatrix m) throws EuclidRuntimeException
m - data to appendEuclidRuntimeException - m.rows and this.rows differpublic void appendRowData(RealArray f) throws EuclidRuntimeException
f - data to appendEuclidRuntimeException - m.cols and this.cols differpublic void appendRowData(RealMatrix m) throws EuclidRuntimeException
m - data to appendEuclidRuntimeException - m.cols and this.cols differpublic void replaceSubMatrixData(int low_row,
int low_col,
RealMatrix m)
low_row - starting rowlow_col - starting colm - data to appendpublic RealMatrix reorderColumnsBy(IntSet is) throws EuclidRuntimeException
is - indexes to reorder byEuclidRuntimeException - is.size() and this.cols differpublic RealMatrix reorderRowsBy(IntSet is) throws EuclidRuntimeException
is - indexes to reprder byEuclidRuntimeException - is.size() and this.rows differpublic RealMatrix extractSubMatrixData(int low_row, int high_row, int low_col, int high_col) throws EuclidRuntimeException
low_row - starting rowhigh_row - end rowlow_col - starting colhigh_col - end colEuclidRuntimeException - low/high_row/col are outside range of thispublic Real2Array extractColumns(int col1, int col2) throws EuclidRuntimeException
col1 - col2 - EuclidRuntimeException - bad values of columnspublic Real2Array extractRows(int row1, int row2) throws EuclidRuntimeException
row1 - row2 - EuclidRuntimeException - bad values of rowspublic IntMatrix elementsInRange(RealRange r) throws EuclidRuntimeException
r - the rangeEuclidRuntimeException - bad values of rowspublic RealMatrix format(int places)
places - public String toString()
public void writeXML(Writer w) throws IOException
w - the writerIOExceptionpublic RealMatrix createMatrixWithOriginShifted(double deltax, double deltay)
public RealMatrix scaleAndInterpolate(int newRows, int newCols)
Copyright © 1994–2024 Peter Murray-Rust. All rights reserved.