Class SimpleBase<T extends SimpleBase<T>>
- All Implemented Interfaces:
Serializable
,ConstMatrix<T>
- Direct Known Subclasses:
SimpleMatrix
SimpleMatrix
implements all the standard matrix operations and uses
generics to allow the returned matrix type to be changed. This class should be extended
instead of SimpleMatrix.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected AutomaticSimpleMatrixConvert
protected Matrix
Internal matrix which this is a wrapper around.protected SimpleOperations
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
bits()
Size of internal array elements.cols
(int begin, int end) Extracts the specified columns from the matrix.combine
(int insertRow, int insertCol, ConstMatrix<?> _B) Creates a new matrix that is a combination of this matrix and matrix B.concatColumns
(ConstMatrix<?>... matrices) Concatenates all the matrices together along their columns.concatRows
(ConstMatrix<?>... matrices) Concatenates all the matrices together along their columns.double
The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b.Returns the complex conjugate of this matrix.void
Switches from a real to complex matrixvoid
Switches from a sparse to dense matrixvoid
Switches from a dense to sparse matrixcopy()
Creates and returns a matrix which is identical to this one.protected T
createComplexMatrix
(int numRows, int numCols) Creates a complex matrix with the same floating type as 'this'Creates a matrix that is the same type and shapeprotected abstract T
createMatrix
(int numRows, int numCols, MatrixType type) Used internally for creating new instances of SimpleMatrix.protected T
createRealMatrix
(int numRows, int numCols) Creates a real matrix with the same floating type as 'this'double
Computes the determinant of the matrix.Computes the determinant of a complex matrix.diag()
If a vector then a square matrix is returned if a matrix then a vector of diagonal ements is returneddivide
(double val) Returns the result of dividing each element by 'val': bi,j = ai,j/valdouble
dot
(ConstMatrix<?> _v) Computes the dot product (a.k.a.eig()
Returns the Eigen Value Decomposition (EVD) of this matrix.elementDiv
(ConstMatrix<?> _B) Returns a matrix which is the result of an element by element division of 'this' and 'b': ci,j = ai,j/bi,jReturns a matrix which is the result of an element by element exp of 'this' ci,j = Math.exp(ai,j)Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.log(ai,j)double
Returns the maximum real value of all the elements in this matrix.double
Returns the maximum absolute value of all the elements in this matrix.double
Returns the minimum real value of all the elements in this matrix.double
Returns the minimum absolute value of all the elements in this matrix.elementMult
(ConstMatrix<?> _B) Returns a matrix which is the result of an element by element multiplication of 'this' and 'b': ci,j = ai,j*bi,jApplies a user defined complex-valued function to a real or complex-valued matrix.Applies a user defined real-valued function to a real-valued matrix.elementPower
(double b) Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ belementPower
(ConstMatrix<?> _B) Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ bi,jdouble
Computes the sum of all the elements in the matrix.Computes the sum of all the elements in the matrix.void
Allows you to perform an equation in-place on this matrix by specifying the right hand side.extractMatrix
(int y0, int y1, int x0, int x1) Creates a new SimpleMatrix which is a submatrix of this matrix.extractVector
(boolean extractRow, int element) Extracts a row or column from this matrix.void
fill
(double val) Sets all the elements in this matrix equal to the specified value.
aij = valvoid
fillComplex
(double real, double imaginary) In-place fills the matrix with a complex value.double
get
(int index) Returns the value of the matrix at the specified index of the 1D row major array.double
get
(int row, int col) Returns the value of the specified matrix element.void
get
(int row, int col, Complex_F64 output) Used to get the complex value of a matrix element.getCDRM()
getColumn
(int col) Returns the specified column in 'this' matrix as a column vector.getDDRM()
getDSCC()
getFDRM()
getFSCC()
double
getImaginary
(int row, int col) Returns the imaginary component of the element.int
getIndex
(int row, int col) Returns the index in the matrix's array.<InnerType extends Matrix>
InnerTypeReturns a reference to the matrix that it uses internally.int
Returns the number of columns in this matrix.int
Returns the number of rows in this matrix.double
getReal
(int row, int col) Returns the real component of the element.getRow
(int row) Returns the specified row in 'this' matrix as a row vector.getType()
Returns the type of matrix it is wrapping.getZDRM()
boolean
Checks to see if any of the elements in this matrix are either NaN or infinite.Returns a matrix that contains the imaginary valued portion of a complex matrix.void
insertIntoThis
(int insertRow, int insertCol, T B) Copy matrix B into this matrix at location (insertRow, insertCol).invert()
Returns the inverse of this matrix.
b = a-1void
boolean
isIdentical
(ConstMatrix<?> _a, double tol) Checks to see if matrix 'a' is the same as this matrix within the specified tolerance.boolean
isInBounds
(int row, int col) Returns true of the specified matrix element is valid element inside this matrix.boolean
isVector()
Returns true if this matrix is a vector.iterator
(boolean rowMajor, int minRow, int minCol, int maxRow, int maxCol) Creates a new iterator for traversing through a submatrix inside this matrix.kron
(ConstMatrix<?> _B) Computes the Kronecker product between this matrix and the provided B matrix:
C = kron(A,B)Loads a new matrix from a CSV file.protected static SimpleOperations
lookupOps
(MatrixType type) Returns a real matrix that has the complex magnitude of each element in the matrix.minus
(double b) Returns the result of matrix-double subtraction:
c = a - b
where c is the returned matrix, a is this matrix, and b is the passed in double.minus
(ConstMatrix<?> _B) Returns the result of matrix subtraction:
c = a - b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.minusComplex
(double real, double imag) Subtracts a complex scalar from each element in the matrix.mult
(ConstMatrix<?> _B) Returns a matrix which is the result of matrix multiplication:
c = a * b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.negative()
Returns a new matrix whose elements are the negative of 'this' matrix's elements.
bij = -aijdouble
normF()
Computes the Frobenius normal of the matrix:
normF = Sqrt{ ∑i=1:m ∑j=1:n { aij2} }int
numCols()
Deprecated.Inconsistent API.int
numRows()
Deprecated.Inconsistent API.plus
(double b) Returns the result of scalar addition:
c = a + b
where c is the returned matrix, a is this matrix, and b is the passed in double.plus
(double beta, ConstMatrix<?> _B) Performs a matrix addition and scale operation.
c = a + β*b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.plus
(ConstMatrix<?> _B) Returns the result of matrix addition:
c = a + b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.plusComplex
(double real, double imag) Adds a complex scalar from each element in the matrix.void
print()
Prints the matrix to standard out.void
Prints the matrix to standard out given aPrintStream.printf(java.lang.String, java.lang.Object...)
style floating point format, e.g.void
Prints the number of rows and column in this matrix.Computes the Moore-Penrose pseudo-inversereal()
Returns a matrix that contains the real valued portion of a complex matrix.void
reshape
(int numRows, int numCols) Reshapes the matrix to the specified number of rows and columns.rows
(int begin, int end) Extracts the specified rows from the matrix.void
saveToFileCSV
(String fileName) Saves this matrix to a file in a CSV format.void
saveToMatrixMarket
(String fileName) Saves this matrix to a file in a matrix market format.scale
(double val) Returns the result of scaling each element by 'val':
bi,j = val*ai,jscaleComplex
(double real, double imag) Scales/multiplies each element in the matrix by the complex number.void
set
(int index, double value) Assigns an element a value based on its index in the internal array.void
set
(int row, int col, double value) Assigns the element in the Matrix to the specified value.void
set
(int row, int col, double real, double imaginary) Used to set the complex value of a matrix element.void
set
(int row, int col, Complex_F64 value) Used to set the complex value of a matrix element.void
setColumn
(int column, int startRow, double... values) Assigns consecutive elements inside a column to the provided array.
A(offset:(offset + values.length),column) = valuesvoid
setColumn
(int column, ConstMatrix<?> src) Copies the vector into the specified column.protected void
void
setRow
(int row, int startColumn, double... values) Assigns consecutive elements inside a row to the provided array.
A(row,offset:(offset + values.length)) = valuesvoid
setRow
(int row, ConstMatrix<?> src) Copies the vector into the specified row.void
Sets the elements in this matrix to be equal to the elements in the passed in matrix.solve
(ConstMatrix<?> _B) Solves for X in the following equation:
x = a-1b
where 'a' is this matrix and 'b' is an n by p matrix.svd()
Computes a full Singular Value Decomposition (SVD) of this matrix with the eigenvalues ordered from largest to smallest.svd
(boolean compact) Computes the SVD in either compact format or full format.double[][]
toArray2()
Returns 2D array of doubles using theget(int, int)
method.toString()
Converts the array into a string format for display purposes.double
trace()
Computes the trace of the matrix.Computes the trace of a complex matrix.Returns the transpose of this matrix.
aTReturns a matrix that is the conjugate transpose.protected abstract T
wrapMatrix
(Matrix m) void
zero()
Sets all the elements in the matrix equal to zero.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.ejml.simple.ConstMatrix
getImag, getNumElements, imag
-
Field Details
-
mat
Internal matrix which this is a wrapper around. -
ops
-
convertType
-
-
Constructor Details
-
SimpleBase
protected SimpleBase(int numRows, int numCols) -
SimpleBase
protected SimpleBase()
-
-
Method Details
-
createMatrix
Used internally for creating new instances of SimpleMatrix. If SimpleMatrix is extended by another class this function should be overridden so that the returned matrices are of the correct type.- Parameters:
numRows
- number of rows in the new matrix.numCols
- number of columns in the new matrix.type
- Type of matrix it should create- Returns:
- A new matrix.
-
createRealMatrix
Creates a real matrix with the same floating type as 'this' -
createComplexMatrix
Creates a complex matrix with the same floating type as 'this' -
wrapMatrix
-
getMatrix
Returns a reference to the matrix that it uses internally. This is useful when an operation is needed that is not provided by this class.
- Returns:
- Reference to the internal DMatrixRMaj.
-
getDDRM
-
getFDRM
-
getZDRM
-
getCDRM
-
getDSCC
-
getFSCC
-
lookupOps
-
transpose
Returns the transpose of this matrix.
aT- Specified by:
transpose
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- A matrix that is n by m.
- See Also:
-
transposeConjugate
Returns a matrix that is the conjugate transpose. If real then this is the same as callingConstMatrix.transpose()
.- Specified by:
transposeConjugate
in interfaceConstMatrix<T extends SimpleBase<T>>
-
mult
Returns a matrix which is the result of matrix multiplication:
c = a * b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.- Specified by:
mult
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- A matrix that is n by p. Not modified.- Returns:
- The results of this operation.
- See Also:
-
kron
Computes the Kronecker product between this matrix and the provided B matrix:
C = kron(A,B)- Specified by:
kron
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- The right matrix in the operation. Not modified.- Returns:
- Kronecker product between this matrix and B.
- See Also:
-
plus
Returns the result of matrix addition:
c = a + b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.- Specified by:
plus
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- m by n matrix. Not modified.- Returns:
- The results of this operation.
-
minus
Returns the result of matrix subtraction:
c = a - b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.- Specified by:
minus
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- m by n matrix. Not modified.- Returns:
- The results of this operation.
- See Also:
-
minus
Returns the result of matrix-double subtraction:
c = a - b
where c is the returned matrix, a is this matrix, and b is the passed in double.NOTE: If the matrix is complex then 'b' will be treated like a complex number with imaginary = 0.
- Specified by:
minus
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
b
- Value subtracted from each element- Returns:
- The results of this operation.
- See Also:
-
minusComplex
Subtracts a complex scalar from each element in the matrix. If the matrix is real, then it will return a complex matrix unless the imaginary component of the scalar is zero.- Specified by:
minusComplex
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
real
- Real component of scalar valueimag
- Imaginary component of scalar value- Returns:
- The results of this operation.
-
plus
Returns the result of scalar addition:
c = a + b
where c is the returned matrix, a is this matrix, and b is the passed in double.NOTE: If the matrix is complex then 'b' will be treated like a complex number with imaginary = 0.
- Specified by:
plus
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
b
- Value added to each element- Returns:
- A matrix that contains the results.
- See Also:
-
plusComplex
Adds a complex scalar from each element in the matrix. If the matrix is real, then it will return a complex matrix unless the imaginary component of the scalar is zero.- Specified by:
plusComplex
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
real
- Real component of scalar valueimag
- Imaginary component of scalar value- Returns:
- The results of this operation.
-
plus
Performs a matrix addition and scale operation.
c = a + β*b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.NOTE: If the matrix is complex then 'b' will be treated like a complex number with imaginary = 0.
- Specified by:
plus
in interfaceConstMatrix<T extends SimpleBase<T>>
_B
- m by n matrix. Not modified.- Returns:
- A matrix that contains the results.
- See Also:
-
dot
Computes the dot product (a.k.a. inner product) between this vector and vector 'v'.- Specified by:
dot
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_v
- The second vector in the dot product. Not modified.- Returns:
- dot product
-
isVector
public boolean isVector()Returns true if this matrix is a vector. A vector is defined as a matrix that has either one row or column.- Specified by:
isVector
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Returns true for vectors and false otherwise.
-
scale
Returns the result of scaling each element by 'val':
bi,j = val*ai,j- Specified by:
scale
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
val
- The multiplication factor. If matrix is complex then the imaginary component is zero.- Returns:
- The scaled matrix.
- See Also:
-
scaleComplex
Scales/multiplies each element in the matrix by the complex number. If the matrix is real, then it will return a complex matrix unless the imaginary component of the scalar is zero.- Specified by:
scaleComplex
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
real
- Real component of scalar valueimag
- Imaginary component of scalar value- Returns:
- Scaled matrix
-
divide
Returns the result of dividing each element by 'val': bi,j = ai,j/val
- Specified by:
divide
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
val
- Divisor. If matrix is complex then the imaginary component is zero.- Returns:
- Matrix with its elements divided by the specified value.
- See Also:
-
invert
Returns the inverse of this matrix.
b = a-1
If the matrix could not be inverted then SingularMatrixException is thrown. Even if no exception is thrown the matrix could still be singular or nearly singular.
- Specified by:
invert
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The inverse of this matrix.
- See Also:
-
pseudoInverse
Computes the Moore-Penrose pseudo-inverse
- Specified by:
pseudoInverse
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- inverse computed using the pseudo inverse.
-
solve
Solves for X in the following equation:
x = a-1b
where 'a' is this matrix and 'b' is an n by p matrix.If the system could not be solved then SingularMatrixException is thrown. Even if no exception is thrown 'a' could still be singular or nearly singular.
- Specified by:
solve
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- n by p matrix. Not modified.- Returns:
- The solution for 'x' that is n by p.
- See Also:
-
setTo
Sets the elements in this matrix to be equal to the elements in the passed in matrix. Both matrix must have the same dimension.- Parameters:
a
- The matrix whose value this matrix is being set to.
-
fill
public void fill(double val) Sets all the elements in this matrix equal to the specified value.
aij = val
- Parameters:
val
- The value each element is set to.- See Also:
-
fillComplex
public void fillComplex(double real, double imaginary) In-place fills the matrix with a complex value. If the matrix is real valued, then it will become a complex matrix. -
zero
public void zero()Sets all the elements in the matrix equal to zero.- See Also:
-
normF
public double normF()Computes the Frobenius normal of the matrix:
normF = Sqrt{ ∑i=1:m ∑j=1:n { aij2} }- Specified by:
normF
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The matrix's Frobenius normal.
- See Also:
-
conditionP2
public double conditionP2()The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b. A value near one indicates that it is a well conditioned matrix.
- Specified by:
conditionP2
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The condition number.
- See Also:
-
determinant
public double determinant()Computes the determinant of the matrix.- Specified by:
determinant
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The determinant.
- See Also:
-
determinantComplex
Computes the determinant of a complex matrix. If the matrix is real then the imaginary component is always zero.- Specified by:
determinantComplex
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The determinant.
- See Also:
-
trace
public double trace()Computes the trace of the matrix.
- Specified by:
trace
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The trace of the matrix.
- See Also:
-
traceComplex
Computes the trace of a complex matrix. If the matrix is real then the imaginary component is always zero.
- Specified by:
traceComplex
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The trace of the matrix.
- See Also:
-
reshape
public void reshape(int numRows, int numCols) Reshapes the matrix to the specified number of rows and columns. If the total number of elements is ≤ number of elements it had before the data is saved. Otherwise a new internal array is declared and the old data lost.
This is equivalent to calling A.getMatrix().reshape(numRows,numCols,false).
- Parameters:
numRows
- The new number of rows in the matrix.numCols
- The new number of columns in the matrix.- See Also:
-
set
public void set(int row, int col, double value) Assigns the element in the Matrix to the specified value. Performs a bounds check to make sure the requested element is part of the matrix.- Parameters:
row
- The row of the element.col
- The column of the element.value
- The element's new value.
-
set
public void set(int index, double value) Assigns an element a value based on its index in the internal array.- Parameters:
index
- The matrix element that is being assigned a value.value
- The element's new value.
-
set
public void set(int row, int col, double real, double imaginary) Used to set the complex value of a matrix element.- Parameters:
row
- The row of the element.col
- The column of the element.real
- Real component of assigned valueimaginary
- Imaginary component of assigned value
-
set
Used to set the complex value of a matrix element.- Parameters:
row
- The row of the element.col
- The column of the element.value
- The value that the element is being assigned to
-
setRow
public void setRow(int row, int startColumn, double... values) Assigns consecutive elements inside a row to the provided array.
A(row,offset:(offset + values.length)) = values- Parameters:
row
- The row that the array is to be written to.startColumn
- The initial column that the array is written to.values
- Values which are to be written to the row in a matrix.
-
setRow
Copies the vector into the specified row. The 'src' vector can be a row or column vector as long as it has the correct length.
- Parameters:
row
- Row in 'this'src
- Vector which is to be copied into the row
-
setColumn
public void setColumn(int column, int startRow, double... values) Assigns consecutive elements inside a column to the provided array.
A(offset:(offset + values.length),column) = values- Parameters:
column
- The column that the array is to be written to.startRow
- The initial column that the array is written to.values
- Values which are to be written to the row in a matrix.
-
setColumn
Copies the vector into the specified column. The 'src' vector can be a row or column vector as long as it has the correct length.
- Parameters:
column
- Column in 'this'src
- Vector which is to be copied into the column
-
get
public double get(int row, int col) Returns the value of the specified matrix element. Performs a bounds check to make sure the requested element is part of the matrix.NOTE: Complex matrices will throw an exception
- Specified by:
get
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
row
- The row of the element.col
- The column of the element.- Returns:
- The value of the element.
-
get
public double get(int index) Returns the value of the matrix at the specified index of the 1D row major array.- Specified by:
get
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
index
- The element's index whose value is to be returned- Returns:
- The value of the specified element.
- See Also:
-
get
Used to get the complex value of a matrix element.- Specified by:
get
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
row
- The row of the element.col
- The column of the element.output
- Storage for the value
-
getReal
public double getReal(int row, int col) Returns the real component of the element. If a real matrix this is the same as callingConstMatrix.get(int, int)
.- Specified by:
getReal
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
row
- The row of the element.col
- The column of the element.
-
getImaginary
public double getImaginary(int row, int col) Returns the imaginary component of the element. If a real matrix this will always be zero.- Specified by:
getImaginary
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
row
- The row of the element.col
- The column of the element.
-
getIndex
public int getIndex(int row, int col) Returns the index in the matrix's array.- Specified by:
getIndex
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
row
- The row number.col
- The column number.- Returns:
- The index of the specified element.
- See Also:
-
iterator
Creates a new iterator for traversing through a submatrix inside this matrix. It can be traversed by row or by column. Range of elements is inclusive, e.g. minRow = 0 and maxRow = 1 will include rows 0 and 1. The iteration starts at (minRow,minCol) and ends at (maxRow,maxCol)- Specified by:
iterator
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
rowMajor
- true means it will traverse through the submatrix by row first, false by columns.minRow
- first row it will start at.minCol
- first column it will start at.maxRow
- last row it will stop at.maxCol
- last column it will stop at.- Returns:
- A new MatrixIterator
-
copy
Creates and returns a matrix which is identical to this one.- Specified by:
copy
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- A new identical matrix.
-
numRows
Deprecated.Inconsistent API. UsegetNumRows()
instead.Returns the number of rows in this matrix.- Returns:
- number of rows.
-
numCols
Deprecated.Inconsistent API. UsegetNumCols()
instead.Returns the number of columns in this matrix.- Returns:
- number of columns.
-
getNumRows
public int getNumRows()Returns the number of rows in this matrix.- Specified by:
getNumRows
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- number of rows.
-
getNumCols
public int getNumCols()Returns the number of columns in this matrix.- Specified by:
getNumCols
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- number of columns.
-
print
public void print()Prints the matrix to standard out.- Specified by:
print
in interfaceConstMatrix<T extends SimpleBase<T>>
-
print
Prints the matrix to standard out given a
PrintStream.printf(java.lang.String, java.lang.Object...)
style floating point format, e.g. print("%f").- Specified by:
print
in interfaceConstMatrix<T extends SimpleBase<T>>
-
toArray2
public double[][] toArray2()Returns 2D array of doubles using theget(int, int)
method.- Specified by:
toArray2
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- 2D array of doubles.
-
toString
Converts the array into a string format for display purposes. The conversion is done using
MatrixIO.print(java.io.PrintStream, DMatrix)
. -
extractMatrix
Creates a new SimpleMatrix which is a submatrix of this matrix.
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.If any of the inputs are set to SimpleMatrix.END then it will be set to the last row or column in the matrix.
- Specified by:
extractMatrix
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
y0
- Start row.y1
- Stop row + 1.x0
- Start column.x1
- Stop column + 1.- Returns:
- The submatrix.
-
extractVector
Extracts a row or column from this matrix. The returned vector will either be a row or column vector depending on the input type.
- Specified by:
extractVector
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
extractRow
- If true a row will be extracted.element
- The row or column the vector is contained in.- Returns:
- Extracted vector.
- See Also:
-
getRow
Returns the specified row in 'this' matrix as a row vector.- Specified by:
getRow
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
row
- Row in the matrix- Returns:
- Extracted vector
- See Also:
-
getColumn
Returns the specified column in 'this' matrix as a column vector.- Specified by:
getColumn
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
col
- Column in the matrix- Returns:
- Extracted vector
- See Also:
-
diag
If a vector then a square matrix is returned if a matrix then a vector of diagonal ements is returned
- Specified by:
diag
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Diagonal elements inside a vector or a square matrix with the same diagonal elements.
- See Also:
-
isIdentical
Checks to see if matrix 'a' is the same as this matrix within the specified tolerance.- Specified by:
isIdentical
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_a
- The matrix it is being compared against.tol
- How similar they must be to be equals.- Returns:
- If they are equal within tolerance of each other.
-
hasUncountable
public boolean hasUncountable()Checks to see if any of the elements in this matrix are either NaN or infinite.- Specified by:
hasUncountable
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- True of an element is NaN or infinite. False otherwise.
-
svd
Computes a full Singular Value Decomposition (SVD) of this matrix with the eigenvalues ordered from largest to smallest.- Returns:
- SVD
-
svd
Computes the SVD in either compact format or full format.- Returns:
- SVD of this matrix.
-
eig
Returns the Eigen Value Decomposition (EVD) of this matrix. -
insertIntoThis
Copy matrix B into this matrix at location (insertRow, insertCol).- Parameters:
insertRow
- First row the matrix is to be inserted into.insertCol
- First column the matrix is to be inserted into.B
- The matrix that is being inserted.
-
combine
Creates a new matrix that is a combination of this matrix and matrix B. B is written into A at the specified location if needed the size of A is increased by growing it. A is grown by padding the new area with zeros.
While useful when adding data to a matrix which will be solved for it is also much less efficient than predeclaring a matrix and inserting data into it.
If insertRow or insertCol is set to SimpleMatrix.END then it will be combined at the last row or column respectively.
- Specified by:
combine
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
insertRow
- Row where matrix B is written in to.insertCol
- Column where matrix B is written in to._B
- The matrix that is written into A.- Returns:
- A new combined matrix.
-
elementMax
public double elementMax()Returns the maximum real value of all the elements in this matrix.- Specified by:
elementMax
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Largest real value of any element.
-
elementMin
public double elementMin()Returns the minimum real value of all the elements in this matrix.- Specified by:
elementMin
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Smallest real value of any element.
-
elementMaxAbs
public double elementMaxAbs()Returns the maximum absolute value of all the elements in this matrix. This is equivalent to the infinite p-norm of the matrix.- Specified by:
elementMaxAbs
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Largest absolute value of any element.
-
elementMinAbs
public double elementMinAbs()Returns the minimum absolute value of all the elements in this matrix.- Specified by:
elementMinAbs
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Smallest absolute value of any element.
-
elementSum
public double elementSum()Computes the sum of all the elements in the matrix. Only works on real matrices.- Specified by:
elementSum
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Sum of all the elements.
-
elementSumComplex
Computes the sum of all the elements in the matrix. Works with both real and complex matrices.- Specified by:
elementSumComplex
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- Sum of all the elements.
-
elementMult
Returns a matrix which is the result of an element by element multiplication of 'this' and 'b': ci,j = ai,j*bi,j
- Specified by:
elementMult
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- A simple matrix.- Returns:
- The element by element multiplication of 'this' and 'b'.
-
elementDiv
Returns a matrix which is the result of an element by element division of 'this' and 'b': ci,j = ai,j/bi,j
- Specified by:
elementDiv
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- A simple matrix.- Returns:
- The element by element division of 'this' and 'b'.
-
elementPower
Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ bi,j
- Specified by:
elementPower
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
_B
- A simple matrix.- Returns:
- The element by element power of 'this' and 'b'.
-
elementPower
Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ b
- Specified by:
elementPower
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
b
- Scalar- Returns:
- The element by element power of 'this' and 'b'.
-
elementExp
Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.exp(ai,j)
- Specified by:
elementExp
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The element by element power of 'this' and 'b'.
-
elementLog
Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.log(ai,j)
- Specified by:
elementLog
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- The element by element power of 'this' and 'b'.
-
elementOp
Applies a user defined real-valued function to a real-valued matrix.
ci,j = op(i, j, ai,j)If the matrix is sparse then this is only applied to non-zero elements
- Specified by:
elementOp
in interfaceConstMatrix<T extends SimpleBase<T>>
-
elementOp
Applies a user defined complex-valued function to a real or complex-valued matrix.
ci,j = op(i, j, ai,j)If the matrix is sparse then this is only applied to non-zero elements
- Specified by:
elementOp
in interfaceConstMatrix<T extends SimpleBase<T>>
-
negative
Returns a new matrix whose elements are the negative of 'this' matrix's elements.
bij = -aij- Specified by:
negative
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- A matrix that is the negative of the original.
-
conjugate
Returns the complex conjugate of this matrix.
- Specified by:
conjugate
in interfaceConstMatrix<T extends SimpleBase<T>>
-
magnitude
Returns a real matrix that has the complex magnitude of each element in the matrix. For a real matrix this is the abs()
- Specified by:
magnitude
in interfaceConstMatrix<T extends SimpleBase<T>>
-
equation
Allows you to perform an equation in-place on this matrix by specifying the right hand side. For information on how to define an equation see
Examples:Equation
. The variable sequence alternates between variable and it's label String. This matrix is by default labeled as 'A', but is a string is the first object in 'variables' then it will take on that value. The variable passed in can be any data type supported by Equation can be passed in. This includes matrices and scalars.
perform("A = A + B",matrix,"B"); // Matrix addition perform("A + B",matrix,"B"); // Matrix addition with implicit 'A = ' perform("A(5,:) = B",matrix,"B"); // Insert a row defined by B into A perform("[A;A]"); // stack A twice with implicit 'A = ' perform("Q = B + 2","Q",matrix,"B"); // Specify the name of 'this' as Q
- Parameters:
equation
- String representing the symbol equationvariables
- List of variable names and variables
-
saveToFileCSV
Saves this matrix to a file in a CSV format. For the file format see
MatrixIO
.- Specified by:
saveToFileCSV
in interfaceConstMatrix<T extends SimpleBase<T>>
- Throws:
IOException
-
saveToMatrixMarket
Saves this matrix to a file in a matrix market format. For the file format see
MatrixIO
.- Specified by:
saveToMatrixMarket
in interfaceConstMatrix<T extends SimpleBase<T>>
- Throws:
IOException
-
loadCSV
Loads a new matrix from a CSV file. For the file format see
MatrixIO
. The returned matrix will be the same matrix type as 'this'.- Parameters:
fileName
- File which is to be loaded.- Returns:
- The matrix.
- Throws:
IOException
- See Also:
-
isInBounds
public boolean isInBounds(int row, int col) Returns true of the specified matrix element is valid element inside this matrix.- Specified by:
isInBounds
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
row
- Row index.col
- Column index.- Returns:
- true if it is a valid element in the matrix.
-
printDimensions
public void printDimensions()Prints the number of rows and column in this matrix. -
bits
public int bits()Size of internal array elements. 32 or 64 bits- Specified by:
bits
in interfaceConstMatrix<T extends SimpleBase<T>>
-
concatColumns
Concatenates all the matrices together along their columns. If the rows do not match the upper elements are set to zero.
A = [ this, m[0] , ... , m[n-1] ]- Specified by:
concatColumns
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
matrices
- Set of matrices- Returns:
- Resulting matrix
-
concatRows
Concatenates all the matrices together along their columns. If the rows do not match the upper elements are set to zero.
A = [ this; m[0] ; ... ; m[n-1] ]- Specified by:
concatRows
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
matrices
- Set of matrices- Returns:
- Resulting matrix
-
rows
Extracts the specified rows from the matrix.- Specified by:
rows
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
begin
- First row (inclusive).end
- Last row (exclusive).- Returns:
- Submatrix that contains the specified rows.
-
cols
Extracts the specified columns from the matrix.- Specified by:
cols
in interfaceConstMatrix<T extends SimpleBase<T>>
- Parameters:
begin
- First column (inclusive).end
- Last column (exclusive).- Returns:
- Submatrix that contains the specified columns.
-
getType
Returns the type of matrix it is wrapping.- Specified by:
getType
in interfaceConstMatrix<T extends SimpleBase<T>>
-
real
Returns a matrix that contains the real valued portion of a complex matrix. For a real valued matrix this will return a copy.- Specified by:
real
in interfaceConstMatrix<T extends SimpleBase<T>>
-
imaginary
Returns a matrix that contains the imaginary valued portion of a complex matrix. For a real valued matrix this will return a matrix full of zeros.- Specified by:
imaginary
in interfaceConstMatrix<T extends SimpleBase<T>>
-
createLike
Creates a matrix that is the same type and shape- Specified by:
createLike
in interfaceConstMatrix<T extends SimpleBase<T>>
- Returns:
- New matrix
-
setMatrix
-
invoke
-
convertToSparse
public void convertToSparse()Switches from a dense to sparse matrix -
convertToDense
public void convertToDense()Switches from a sparse to dense matrix -
convertToComplex
public void convertToComplex()Switches from a real to complex matrix
-