public class SimpleMatrix
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static class |
SimpleMatrix.InversionType
Set the algorithm to be used during inversion
|
static class |
SimpleMatrix.MatrixNormType |
Modifier and Type | Field and Description |
---|---|
static SimpleMatrix |
I_2 |
static SimpleMatrix |
I_3 |
static SimpleMatrix |
I_4 |
Constructor and Description |
---|
SimpleMatrix()
Create an empty matrix.
|
SimpleMatrix(double[][] otherBuffer)
Creates a new matrix from 2x2 double array
|
SimpleMatrix(int rows,
int cols)
Create a matrix with row rows and column cols
|
SimpleMatrix(Jama.Matrix other)
Creates a new matrix from a jama matrix
|
SimpleMatrix(SimpleMatrix otherMat)
Creates a new matrix from another
|
SimpleMatrix(java.lang.String str)
Creates a new matrix from string data
|
Modifier and Type | Method and Description |
---|---|
void |
add(double addend)
Add addend to all entries in matrix in place
|
void |
add(SimpleMatrix... addends)
Method to add a set of matrices to this matrix in place.
|
void |
addToElement(int row,
int col,
double addend)
Add addend to entry at [row,col] in place
|
SimpleMatrix |
clone() |
double |
conditionNumber(SimpleMatrix.MatrixNormType normType) |
double[][] |
copyAsDoubleArray() |
void |
copyTo(double[][] otherBuffer)
Copy matrix entries to supplied 2x2 double array
|
double |
determinant() |
void |
divideBy(double divisor)
Divide all entries in matrix by divisor in place
|
SimpleMatrix |
dividedBy(double divisor)
Divide all entries in matrix by divisor [current matrix is not updated]
|
void |
divideElementBy(int row,
int col,
double divisor)
Divide divisor from entry at [row,col] in place
|
void |
divideElementWiseBy(SimpleMatrix other)
ordered division of matrix entries in place
|
void |
fill(double value)
Sets all matrix entries to the given value.
|
SimpleVector |
getCol(int col)
Retrieve column from index col of matrix
|
int |
getCols() |
SimpleVector |
getDiag() |
double |
getElement(int row,
int col)
Retrieve matrix entry in the specified row and column
|
java.lang.String |
getMatrixSerialization()
return a serialized equivalent of this matix
|
SimpleVector |
getRow(int row)
Retrieve row from index row of matrix
|
int |
getRows() |
SimpleVector |
getSubCol(int firstRow,
int col,
int sizeRows)
Returns a vector containing a sub column in current matrix.
|
SimpleMatrix |
getSubMatrix(int[] selectRows,
int[] selectCols)
Creates a new sub matrix with entries from ordered rows and ordered columns provided
|
SimpleMatrix |
getSubMatrix(int deleteRow,
int deleteCol) |
SimpleMatrix |
getSubMatrix(int firstRow,
int firstCol,
int sizeRows,
int sizeCols)
Creates a new sub matrix of this matrix
|
SimpleVector |
getSubRow(int row,
int firstCol,
int sizeCols)
Returns a vector containing a sub row in current matrix.
|
void |
identity()
Sets the matrix to the identity matrix, i.e.
|
void |
init(double[][] otherBuffer)
Initialize matrix with data from 2x2 double array
|
void |
init(int rows,
int cols)
Initialize zero matrix
|
void |
init(SimpleMatrix otherMat)
Initialize matrix with data from supplied matrix
|
void |
init(java.lang.String str)
Initialize matrix with data string of the form []
|
SimpleMatrix |
inverse(SimpleMatrix.InversionType inversionType)
Inverts the given matrix using the specified inversion method.
|
boolean |
isIdentity(double delta)
Determines if matrix is an identity matrix
|
boolean |
isOrthogonal(double maxErr)
Determines if matrix is orthogonal
|
boolean |
isRigidMotion2D(double maxErr)
Determines if matrix is a rigid motion matrix
|
boolean |
isRigidMotion3D(double maxErr)
Determines if matrix is a rigid motion matrix
|
boolean |
isRotation2D(double maxErr)
Determines if matrix is a rotation matrix
|
boolean |
isRotation3D(double maxErr)
Determines if matrix is a rotation matrix
|
boolean |
isSingular(double delta) |
boolean |
isSpecialOrthogonal(double maxErr) |
boolean |
isSquare() |
boolean |
isUpperTriangular()
Test for upper triangularity of a matrix.
|
SimpleMatrix |
multipliedBy(double factor)
Multiply factor to all entries in matrix [current matrix is not updated]
|
void |
multiplyBy(double factor)
Multiply factor to all entries in matrix in place
|
void |
multiplyElementBy(int row,
int col,
double factor)
Multiply factor to entry at [row,col] in place
|
void |
multiplyElementWiseBy(SimpleMatrix other)
ordered multiplication of matrix entries in place
|
void |
negate()
multiply all the entries in a matrix by -1 in place.
|
SimpleMatrix |
negated() |
double |
norm(SimpleMatrix.MatrixNormType normType) |
void |
ones()
Sets all matrix entries to 1.0.
|
void |
randomize(double min,
double max)
Assigns random values to the entries of the matrix.
|
void |
setColValue(int col,
SimpleVector newCol)
Replace col with newCol
|
void |
setDiagValue(SimpleVector diag)
Replace diagonal entries of matrix with diag
|
void |
setElementValue(int row,
int col,
double val)
Replaces matrix entry in the specified row and column with given value
|
void |
setMatrixSerialization(java.lang.String str)
Initialize matrix using a serialized equivalent
|
void |
setRowValue(int row,
SimpleVector newRow)
Replace row with newRow
|
void |
setSubColValue(int firstRow,
int col,
SimpleVector subCol)
Replace the entries of sub column starting at [col,firstRow] with subCol
|
void |
setSubMatrixValue(int firstRow,
int firstCol,
SimpleMatrix subMatrix)
Replaces matrix entries starting at firsRow and firstCol with entries from subMatrix
|
void |
setSubRowValue(int row,
int firstCol,
SimpleVector subRow)
Replace the entries of sub row starting at [row,firstCol] with subRow
|
void |
subtract(double subtrahend)
Subtract subtrahend from all entries in matrix in place
|
void |
subtract(SimpleMatrix... subtrahends)
Method to subtract a set of matrices to this matrix in place.
|
void |
subtractFromElement(int row,
int col,
double subtrahend)
Subtract subtrahend from entry at [row,col] in place
|
java.lang.String |
toString() |
void |
transpose()
Performs a matrix transpose in place.
|
SimpleMatrix |
transposed() |
void |
zeros()
Sets all matrix entries to 0.0.
|
public static final SimpleMatrix I_2
public static final SimpleMatrix I_3
public static final SimpleMatrix I_4
public SimpleMatrix()
public SimpleMatrix(int rows, int cols)
rows
- is number of rows in matrixcols
- is number of columns in matrixpublic SimpleMatrix(SimpleMatrix otherMat)
otherMat
- is matrix to be copiedpublic SimpleMatrix(double[][] otherBuffer)
otherBuffer
- public SimpleMatrix(java.lang.String str)
str
- is dat stringpublic SimpleMatrix(Jama.Matrix other)
other
- public void init(int rows, int cols)
rows
- number of rowscols
- number of columnspublic void init(SimpleMatrix otherMat)
otherMat
- is source matrixpublic void init(double[][] otherBuffer)
otherBuffer
- is source double arraypublic void init(java.lang.String str)
str
- is data stringpublic SimpleMatrix clone()
clone
in class java.lang.Object
public double[][] copyAsDoubleArray()
public void copyTo(double[][] otherBuffer)
otherBuffer
- is 2x2 double array to be populated with matrix entriespublic int getRows()
public int getCols()
public void fill(double value)
public void zeros()
public void ones()
public void randomize(double min, double max)
min
- The lower bound of the interval the values are drawn from.max
- The upper bound of the interval the values are drawn from. Note that value max
itself is excluded from the interval and therefore never assigned.public void identity()
public double getElement(int row, int col)
row
- is row containing entrycol
- is column containing entrypublic void setElementValue(int row, int col, double val)
row
- is row containing entry to be replacedcol
- is column containing entry to be replacedval
- is value to replace matrix entry in the specified row and columnpublic SimpleMatrix getSubMatrix(int firstRow, int firstCol, int sizeRows, int sizeCols)
firstRow
- is the first row of entries to be copied to sub matrixfirstCol
- is first column of entries to be copied to sub matrixsizeRows
- is number of rows to be copied starting from first rowsizeCols
- is number of columns to be copied starting from first columnpublic SimpleMatrix getSubMatrix(int[] selectRows, int[] selectCols)
selectRows
- is ordered array containing rows to be copiedselectCols
- is ordered array containing columns to be copiedpublic SimpleMatrix getSubMatrix(int deleteRow, int deleteCol)
public void setSubMatrixValue(int firstRow, int firstCol, SimpleMatrix subMatrix)
firstRow
- is row of first element to be replacedfirstCol
- is column of first element to be replacedsubMatrix
- is sub matrix containing entries to replace matrix entriespublic SimpleVector getSubRow(int row, int firstCol, int sizeCols)
row
- is row containing desired sub rowfirstCol
- is the starting column of desired sub rowsizeCols
- is number of columns in sub rowpublic void setSubRowValue(int row, int firstCol, SimpleVector subRow)
row
- is row containing desired sub rowfirstCol
- is the starting column of desired sub rowsubRow
- is vector containing new entriespublic SimpleVector getRow(int row)
row
- is index of row to retrievedpublic void setRowValue(int row, SimpleVector newRow)
row
- is index of row to be replacednewRow
- is vector containing new entriespublic SimpleVector getSubCol(int firstRow, int col, int sizeRows)
col
- is index of column containing desired sub columnfirstRow
- is the starting column of desired sub columnsizeRows
- is number of columns in sub columnpublic void setSubColValue(int firstRow, int col, SimpleVector subCol)
col
- is index of column containing desired sub columnfirstRow
- is the starting row of desired sub columnsubCol
- is vector containing new entriespublic SimpleVector getCol(int col)
col
- is index of column to retrievedpublic void setColValue(int col, SimpleVector newCol)
col
- is index of column to be replacednewCol
- is vector containing new entriespublic SimpleVector getDiag()
public void setDiagValue(SimpleVector diag)
diag
- is vector containing new entriespublic void addToElement(int row, int col, double addend)
row
- of entry to be updatedcol
- of entry to be updatedaddend
- is value to be added to entry at [row,col]public void subtractFromElement(int row, int col, double subtrahend)
row
- of entry to be updatedcol
- of entry to be updatedsubtrahend
- is value to be subtracted from entry at [row,col]public void multiplyElementBy(int row, int col, double factor)
row
- of entry to be updatedcol
- of entry to be updatedfactor
- is value to be multiplied to entry at [row,col]public void divideElementBy(int row, int col, double divisor)
row
- of entry to be updatedcol
- of entry to be updateddivisor
- is value to be divided from entry at [row,col]public void add(double addend)
addend
- is value to be added to all entries in matrixpublic void subtract(double subtrahend)
subtrahend
- is value to be subtracted from all entries in matrixpublic void multiplyBy(double factor)
factor
- is value to be multiplied to all entries in matrixpublic SimpleMatrix multipliedBy(double factor)
factor
- is value to be multiplied to all entries in matrixpublic void divideBy(double divisor)
divisor
- is value to be divided from all entries in matrixpublic SimpleMatrix dividedBy(double divisor)
divisor
- is value to be divided from all entries in matrixpublic void add(SimpleMatrix... addends)
addends
- are set of matrices to be added to this matrix.public void subtract(SimpleMatrix... subtrahends)
subtrahends
- are set of matrices to be from this matrix.public void multiplyElementWiseBy(SimpleMatrix other)
other
- public void divideElementWiseBy(SimpleMatrix other)
other
- public void negate()
public SimpleMatrix negated()
public void transpose()
public SimpleMatrix transposed()
public double norm(SimpleMatrix.MatrixNormType normType)
public double determinant()
public double conditionNumber(SimpleMatrix.MatrixNormType normType)
public boolean isSquare()
public boolean isIdentity(double delta)
delta
- is error tolerancepublic boolean isSingular(double delta)
public boolean isUpperTriangular()
public boolean isOrthogonal(double maxErr)
maxErr
- is tolerancepublic boolean isSpecialOrthogonal(double maxErr)
public boolean isRotation2D(double maxErr)
maxErr
- public boolean isRotation3D(double maxErr)
maxErr
- public boolean isRigidMotion2D(double maxErr)
maxErr
- public boolean isRigidMotion3D(double maxErr)
maxErr
- public SimpleMatrix inverse(SimpleMatrix.InversionType inversionType)
inversionType
- The type of inversion to be used.public java.lang.String getMatrixSerialization()
public void setMatrixSerialization(java.lang.String str)
str
- public java.lang.String toString()
toString
in class java.lang.Object