Package jisa.maths.matrices
Class ComplexMatrix
- java.lang.Object
-
- jisa.maths.matrices.ComplexMatrix
-
- All Implemented Interfaces:
java.lang.Iterable<org.apache.commons.math.complex.Complex>,Matrix<org.apache.commons.math.complex.Complex>
- Direct Known Subclasses:
ComplexMatrix.Col,ComplexMatrix.Identity,ComplexMatrix.Row
public class ComplexMatrix extends java.lang.Object implements Matrix<org.apache.commons.math.complex.Complex>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classComplexMatrix.Colstatic classComplexMatrix.Identitystatic classComplexMatrix.Row-
Nested classes/interfaces inherited from interface jisa.maths.matrices.Matrix
Matrix.EntryConsumer<T>, Matrix.EntryMapper<U,T>, Matrix.LinearMapper<T>
-
-
Constructor Summary
Constructors Constructor Description ComplexMatrix(int rows, int cols)ComplexMatrix(int rows, int cols, org.apache.commons.math.complex.Complex... values)ComplexMatrix(Matrix<org.apache.commons.math.complex.Complex> matrix)ComplexMatrix(org.apache.commons.math.complex.Complex[][] data)ComplexMatrix(org.apache.commons.math.linear.FieldMatrix<org.apache.commons.math.complex.Complex> matrix)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ComplexMatrixadd(Matrix<org.apache.commons.math.complex.Complex> rhs)Adds the given matrix to this one.ComplexMatrixadd(org.apache.commons.math.complex.Complex rhs)Add the given value to each element in this matrix, returning the result.voidaddToElement(int row, int col, org.apache.commons.math.complex.Complex value)Replace the value of an element with itself plus a given value.ComplexMatrixappendCols(Matrix<org.apache.commons.math.complex.Complex> cols)Creates a new matrix consisting of the given columns appended to the right of this matrix.ComplexMatrixappendRows(Matrix<org.apache.commons.math.complex.Complex> rows)Creates a new matrix consisting of the given rows appended to the bottom of this matrix.intcols()Returns the number of columns in the matrix.ComplexMatrixcopy()Returns a deep copy of the matrix.ComplexMatrixdivide(org.apache.commons.math.complex.Complex rhs)Divides all elements in this matrix by the given value.voiddivideElement(int row, int col, org.apache.commons.math.complex.Complex value)Replace the value of an element with itself divided by a given value.ComplexMatrixelementDivide(Matrix<org.apache.commons.math.complex.Complex> rhs)Performs element-wise division of this matrix by the specified matrix (divides each element in this matrix by its corresponding element in the other).ComplexMatrixelementMultiply(Matrix<org.apache.commons.math.complex.Complex> rhs)Computes the element-wise product of this matrix with another (this .* other).org.apache.commons.math.linear.FieldMatrix<org.apache.commons.math.complex.Complex>fieldMatrix()org.apache.commons.math.complex.Complexget(int row, int col)Returns the element at the given indices.org.apache.commons.math.complex.Complex[]getColArray(int col)Returns the values in a single column as an array.ComplexMatrixgetColMatrix(int col)Returns a single column as a column matrix.ComplexMatrixgetColSums()Returns a row matrix of the sums of each column in this matrix.org.apache.commons.math.complex.Complex[][]getData()Returns all elements as a 2-dimensional array.org.apache.commons.math.complex.ComplexgetDeterminant()Returns the determinant of the matrix (only for square matrices).ComplexMatrixgetDiagonal()Returns the diagonal values of the square matrix as a column matrix.org.apache.commons.math.complex.Complex[]getFlatData()Returns all elements in a 1-dimensional array.LU<org.apache.commons.math.complex.Complex>getLU()Computes and returns the LU decomposition of this matrix (only for square matrices).QR<org.apache.commons.math.complex.Complex>getQR()Computes and returns the QR decomposition of this matrix.org.apache.commons.math.complex.Complex[]getRowArray(int row)Returns the values in a single row as an array.ComplexMatrixgetRowMatrix(int row)Returns a single row as a row matrix.ComplexMatrixgetRowSums()Returns a column matrix of the sums of each row in this matrix.ComplexMatrixgetSubMatrix(int[] rows, int[] cols)Returns a sub-matrix containing only the specified rows and columns from this matrix.ComplexMatrixgetSubMatrix(int startRow, int endRow, int startCol, int endCol)Returns a sub-matrix containing only the rows and columns specified in the given ranges (inclusive).org.apache.commons.math.complex.ComplexgetTrace()Returns the trace of the matrix (sum of diagonal elements).ComplexMatrixinvert()Inverts the matrix and returns the result (only for square matrices).booleanisSingular()Returns whether the matrix is singular (has no inverse).ComplexMatrixleftDivide(Matrix<org.apache.commons.math.complex.Complex> rhs)Multiplies the supplied matrix by the inverse of this matrix.ComplexMatrixleftDivide(org.apache.commons.math.complex.Complex lhs)Divides the given value by each element in the matrix returning a matrix of the results.ComplexMatrixleftElementDivide(Matrix<org.apache.commons.math.complex.Complex> lhs)Performs element-wise division of the specified matrix by this matrix (divides each element in the supplied matrix by its corresponding element in this matrix).ComplexMatrixleftElementMultiply(Matrix<org.apache.commons.math.complex.Complex> lhs)Computes the element-wise product of another matrix with this matrix (other * this).ComplexMatrixleftMultiply(Matrix<org.apache.commons.math.complex.Complex> lhs)Multiplies another matrix by this matrix (other * this).ComplexMatrixleftMultiply(org.apache.commons.math.complex.Complex lhs)Pre-multiplies each element in this matrix by a scalar value.ComplexMatrixmap(GFunction<org.apache.commons.math.complex.Complex,org.apache.commons.math.complex.Complex> mapper)Map all elements of this matrix into a new matrix according to the provided mapping function.ComplexMatrixmap(Matrix.EntryMapper<org.apache.commons.math.complex.Complex,org.apache.commons.math.complex.Complex> mapper)Map all elements of this matrix into a new matrix according to the provided mapping function.voidmapCol(int col, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Maps the values of a specified column onto themselves.voidmapColToCol(int source, int dest, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Maps one column onto another.voidmapElement(int row, int col, GFunction<org.apache.commons.math.complex.Complex,org.apache.commons.math.complex.Complex> mapper)Replace an element with the value of a function of itself.voidmapRow(int row, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Maps the values of a specified row onto themselves.voidmapRowToRow(int source, int dest, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Maps one row onto another.ComplexMatrixmultiply(Matrix<org.apache.commons.math.complex.Complex> rhs)Multiplies this matrix by another (this * other).ComplexMatrixmultiply(org.apache.commons.math.complex.Complex rhs)Multiplies each element in this matrix by a scalar value.voidmultiplyElement(int row, int col, org.apache.commons.math.complex.Complex value)Replace the value of an element with itself multiplied by a given value.ComplexMatrixreshape(int rows, int cols)Reshapes the elements in the matrix into a matrix of different dimensions (but same total number of elements), returning the result.introws()Returns the number of rows in the matrix.voidset(int row, int col, org.apache.commons.math.complex.Complex value)Sets the matrix element at the given (row, col) position.voidsetAll(org.apache.commons.math.complex.Complex value)Sets all elements to a single value.voidsetAll(org.apache.commons.math.complex.Complex... values)Sets all elements in the matrix.voidsetDiagonal(org.apache.commons.math.complex.Complex value)Sets the values along the leading diagonal to the same value.voidsetDiagonal(org.apache.commons.math.complex.Complex... values)Sets the elements on the leading diagonal of the matrix.ComplexMatrixsubtract(Matrix<org.apache.commons.math.complex.Complex> rhs)Subtracts the given matrix from this one, returning the result.ComplexMatrixsubtract(org.apache.commons.math.complex.Complex rhs)Subtracts the given value from each element in this matrix, returning the result.voidsubtractFromElement(int row, int col, org.apache.commons.math.complex.Complex value)Replace the value of an element with itself minus a given value.java.lang.StringtoString()Returns a textual representation of this matrix.ComplexMatrixtranspose()Transposes the matrix and returns the result.-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jisa.maths.matrices.Matrix
checkIndices, div, div, divide, equals, forEach, forEach, forEachCol, forEachRow, isCol, isRow, isSquare, iterator, map, map, mapCol, mapColToCol, mapRow, mapRowToRow, mapSelf, mapSelf, minus, minus, plus, plus, setCol, setCol, setRow, setRow, setSubMatrix, size, stream, times, times
-
-
-
-
Constructor Detail
-
ComplexMatrix
public ComplexMatrix(int rows, int cols)
-
ComplexMatrix
public ComplexMatrix(int rows, int cols, org.apache.commons.math.complex.Complex... values)
-
ComplexMatrix
public ComplexMatrix(org.apache.commons.math.complex.Complex[][] data)
-
ComplexMatrix
public ComplexMatrix(org.apache.commons.math.linear.FieldMatrix<org.apache.commons.math.complex.Complex> matrix)
-
ComplexMatrix
public ComplexMatrix(Matrix<org.apache.commons.math.complex.Complex> matrix)
-
-
Method Detail
-
toString
public java.lang.String toString()
Description copied from interface:MatrixReturns a textual representation of this matrix.
-
fieldMatrix
public org.apache.commons.math.linear.FieldMatrix<org.apache.commons.math.complex.Complex> fieldMatrix()
-
rows
public int rows()
Description copied from interface:MatrixReturns the number of rows in the matrix.
-
cols
public int cols()
Description copied from interface:MatrixReturns the number of columns in the matrix.
-
get
public org.apache.commons.math.complex.Complex get(int row, int col)Description copied from interface:MatrixReturns the element at the given indices.
-
getData
public org.apache.commons.math.complex.Complex[][] getData()
Description copied from interface:MatrixReturns all elements as a 2-dimensional array.
-
getFlatData
public org.apache.commons.math.complex.Complex[] getFlatData()
Description copied from interface:MatrixReturns all elements in a 1-dimensional array.- Specified by:
getFlatDatain interfaceMatrix<org.apache.commons.math.complex.Complex>- Returns:
- All elements
-
getDiagonal
public ComplexMatrix getDiagonal()
Description copied from interface:MatrixReturns the diagonal values of the square matrix as a column matrix.- Specified by:
getDiagonalin interfaceMatrix<org.apache.commons.math.complex.Complex>- Returns:
- Diagonal values
-
set
public void set(int row, int col, org.apache.commons.math.complex.Complex value)Description copied from interface:MatrixSets the matrix element at the given (row, col) position.
-
setAll
public void setAll(org.apache.commons.math.complex.Complex... values)
Description copied from interface:MatrixSets all elements in the matrix.
-
setDiagonal
public void setDiagonal(org.apache.commons.math.complex.Complex... values)
Description copied from interface:MatrixSets the elements on the leading diagonal of the matrix. Matrix must be square.- Specified by:
setDiagonalin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
values- Diagonal elements
-
setDiagonal
public void setDiagonal(org.apache.commons.math.complex.Complex value)
Description copied from interface:MatrixSets the values along the leading diagonal to the same value. Matrix must be square.- Specified by:
setDiagonalin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
value- Element value
-
setAll
public void setAll(org.apache.commons.math.complex.Complex value)
Description copied from interface:MatrixSets all elements to a single value.
-
mapElement
public void mapElement(int row, int col, GFunction<org.apache.commons.math.complex.Complex,org.apache.commons.math.complex.Complex> mapper)Description copied from interface:MatrixReplace an element with the value of a function of itself.- Specified by:
mapElementin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
row- Row indexcol- Column indexmapper- Function for mapping
-
multiplyElement
public void multiplyElement(int row, int col, org.apache.commons.math.complex.Complex value)Description copied from interface:MatrixReplace the value of an element with itself multiplied by a given value.- Specified by:
multiplyElementin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
row- Row indexcol- Column indexvalue- Factor to multiply by
-
divideElement
public void divideElement(int row, int col, org.apache.commons.math.complex.Complex value)Description copied from interface:MatrixReplace the value of an element with itself divided by a given value.- Specified by:
divideElementin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
row- Row indexcol- Column indexvalue- Factor to divide by
-
addToElement
public void addToElement(int row, int col, org.apache.commons.math.complex.Complex value)Description copied from interface:MatrixReplace the value of an element with itself plus a given value.- Specified by:
addToElementin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
row- Row indexcol- Column indexvalue- Value to add
-
subtractFromElement
public void subtractFromElement(int row, int col, org.apache.commons.math.complex.Complex value)Description copied from interface:MatrixReplace the value of an element with itself minus a given value.- Specified by:
subtractFromElementin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
row- Row indexcol- Column indexvalue- Value to subtract
-
mapRow
public void mapRow(int row, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Description copied from interface:MatrixMaps the values of a specified row onto themselves.
-
mapCol
public void mapCol(int col, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Description copied from interface:MatrixMaps the values of a specified column onto themselves.
-
mapRowToRow
public void mapRowToRow(int source, int dest, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Description copied from interface:MatrixMaps one row onto another.- Specified by:
mapRowToRowin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
source- Source row indexdest- Destination row indexmapper- Function that defines mapping
-
mapColToCol
public void mapColToCol(int source, int dest, Matrix.LinearMapper<org.apache.commons.math.complex.Complex> mapper)Description copied from interface:MatrixMaps one column onto another.- Specified by:
mapColToColin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
source- Source column indexdest- Destination column indexmapper- Function that defines mapping
-
getRowArray
public org.apache.commons.math.complex.Complex[] getRowArray(int row)
Description copied from interface:MatrixReturns the values in a single row as an array.- Specified by:
getRowArrayin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
row- Row index- Returns:
- Array of values
-
getColArray
public org.apache.commons.math.complex.Complex[] getColArray(int col)
Description copied from interface:MatrixReturns the values in a single column as an array.- Specified by:
getColArrayin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
col- Column index- Returns:
- Array of values
-
getRowMatrix
public ComplexMatrix getRowMatrix(int row)
Description copied from interface:MatrixReturns a single row as a row matrix.- Specified by:
getRowMatrixin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
row- Row index- Returns:
- Row matrix
-
getColMatrix
public ComplexMatrix getColMatrix(int col)
Description copied from interface:MatrixReturns a single column as a column matrix.- Specified by:
getColMatrixin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
col- Column index- Returns:
- Column matrix
-
multiply
public ComplexMatrix multiply(Matrix<org.apache.commons.math.complex.Complex> rhs)
Description copied from interface:MatrixMultiplies this matrix by another (this * other).
-
leftMultiply
public ComplexMatrix leftMultiply(Matrix<org.apache.commons.math.complex.Complex> lhs)
Description copied from interface:MatrixMultiplies another matrix by this matrix (other * this).- Specified by:
leftMultiplyin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
lhs- Matrix to multiply (left-hand side)- Returns:
- Result of multiplication
-
multiply
public ComplexMatrix multiply(org.apache.commons.math.complex.Complex rhs)
Description copied from interface:MatrixMultiplies each element in this matrix by a scalar value.
-
leftMultiply
public ComplexMatrix leftMultiply(org.apache.commons.math.complex.Complex lhs)
Description copied from interface:MatrixPre-multiplies each element in this matrix by a scalar value.- Specified by:
leftMultiplyin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
lhs- Scalar value.- Returns:
- Result of multiplication
-
elementMultiply
public ComplexMatrix elementMultiply(Matrix<org.apache.commons.math.complex.Complex> rhs)
Description copied from interface:MatrixComputes the element-wise product of this matrix with another (this .* other).- Specified by:
elementMultiplyin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
rhs- Matrix to multiply by (right-hand side)- Returns:
- Result of multiplication
-
leftElementMultiply
public ComplexMatrix leftElementMultiply(Matrix<org.apache.commons.math.complex.Complex> lhs)
Description copied from interface:MatrixComputes the element-wise product of another matrix with this matrix (other * this).- Specified by:
leftElementMultiplyin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
lhs- Matrix to multiply (left-hand side)- Returns:
- Result of multiplication
-
elementDivide
public ComplexMatrix elementDivide(Matrix<org.apache.commons.math.complex.Complex> rhs)
Description copied from interface:MatrixPerforms element-wise division of this matrix by the specified matrix (divides each element in this matrix by its corresponding element in the other).- Specified by:
elementDividein interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
rhs- Matrix to divide by- Returns:
- Result of division
-
leftElementDivide
public ComplexMatrix leftElementDivide(Matrix<org.apache.commons.math.complex.Complex> lhs)
Description copied from interface:MatrixPerforms element-wise division of the specified matrix by this matrix (divides each element in the supplied matrix by its corresponding element in this matrix).- Specified by:
leftElementDividein interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
lhs- Matrix to divide- Returns:
- Result of division
-
divide
public ComplexMatrix divide(org.apache.commons.math.complex.Complex rhs)
Description copied from interface:MatrixDivides all elements in this matrix by the given value.
-
leftDivide
public ComplexMatrix leftDivide(org.apache.commons.math.complex.Complex lhs)
Description copied from interface:MatrixDivides the given value by each element in the matrix returning a matrix of the results.- Specified by:
leftDividein interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
lhs- Value to be divided- Returns:
- Result of division
-
add
public ComplexMatrix add(Matrix<org.apache.commons.math.complex.Complex> rhs)
Description copied from interface:MatrixAdds the given matrix to this one. (Adds each element with its corresponding element).
-
add
public ComplexMatrix add(org.apache.commons.math.complex.Complex rhs)
Description copied from interface:MatrixAdd the given value to each element in this matrix, returning the result.
-
subtract
public ComplexMatrix subtract(Matrix<org.apache.commons.math.complex.Complex> rhs)
Description copied from interface:MatrixSubtracts the given matrix from this one, returning the result.
-
subtract
public ComplexMatrix subtract(org.apache.commons.math.complex.Complex rhs)
Description copied from interface:MatrixSubtracts the given value from each element in this matrix, returning the result.
-
map
public ComplexMatrix map(Matrix.EntryMapper<org.apache.commons.math.complex.Complex,org.apache.commons.math.complex.Complex> mapper)
Description copied from interface:MatrixMap all elements of this matrix into a new matrix according to the provided mapping function.
-
map
public ComplexMatrix map(GFunction<org.apache.commons.math.complex.Complex,org.apache.commons.math.complex.Complex> mapper)
Description copied from interface:MatrixMap all elements of this matrix into a new matrix according to the provided mapping function.
-
copy
public ComplexMatrix copy()
Description copied from interface:MatrixReturns a deep copy of the matrix.
-
getSubMatrix
public ComplexMatrix getSubMatrix(int[] rows, int[] cols)
Description copied from interface:MatrixReturns a sub-matrix containing only the specified rows and columns from this matrix.- Specified by:
getSubMatrixin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
rows- Array of row indicescols- Array of column indices- Returns:
- Sub-matrix
-
getSubMatrix
public ComplexMatrix getSubMatrix(int startRow, int endRow, int startCol, int endCol)
Description copied from interface:MatrixReturns a sub-matrix containing only the rows and columns specified in the given ranges (inclusive).- Specified by:
getSubMatrixin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
startRow- Start of row rangeendRow- End of row rangestartCol- Start of column rangeendCol- End of column range- Returns:
- Sub-matrix
-
appendRows
public ComplexMatrix appendRows(Matrix<org.apache.commons.math.complex.Complex> rows)
Description copied from interface:MatrixCreates a new matrix consisting of the given rows appended to the bottom of this matrix.- Specified by:
appendRowsin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
rows- Rows to append (must match column dimension)- Returns:
- Combined matrix
-
appendCols
public ComplexMatrix appendCols(Matrix<org.apache.commons.math.complex.Complex> cols)
Description copied from interface:MatrixCreates a new matrix consisting of the given columns appended to the right of this matrix.- Specified by:
appendColsin interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
cols- Columns to append (must match row dimension)- Returns:
- Combined matrix
-
isSingular
public boolean isSingular()
Description copied from interface:MatrixReturns whether the matrix is singular (has no inverse).- Specified by:
isSingularin interfaceMatrix<org.apache.commons.math.complex.Complex>- Returns:
- Singular?
-
getDeterminant
public org.apache.commons.math.complex.Complex getDeterminant()
Description copied from interface:MatrixReturns the determinant of the matrix (only for square matrices).- Specified by:
getDeterminantin interfaceMatrix<org.apache.commons.math.complex.Complex>- Returns:
- Determinant value
-
getTrace
public org.apache.commons.math.complex.Complex getTrace()
Description copied from interface:MatrixReturns the trace of the matrix (sum of diagonal elements).
-
invert
public ComplexMatrix invert()
Description copied from interface:MatrixInverts the matrix and returns the result (only for square matrices).
-
transpose
public ComplexMatrix transpose()
Description copied from interface:MatrixTransposes the matrix and returns the result.
-
reshape
public ComplexMatrix reshape(int rows, int cols)
Description copied from interface:MatrixReshapes the elements in the matrix into a matrix of different dimensions (but same total number of elements), returning the result.rows * cols must equal this.size().
-
leftDivide
public ComplexMatrix leftDivide(Matrix<org.apache.commons.math.complex.Complex> rhs)
Description copied from interface:MatrixMultiplies the supplied matrix by the inverse of this matrix.- Specified by:
leftDividein interfaceMatrix<org.apache.commons.math.complex.Complex>- Parameters:
rhs- Matrix to be "divided"- Returns:
- Result of division
-
getQR
public QR<org.apache.commons.math.complex.Complex> getQR()
Description copied from interface:MatrixComputes and returns the QR decomposition of this matrix.
-
getLU
public LU<org.apache.commons.math.complex.Complex> getLU()
Description copied from interface:MatrixComputes and returns the LU decomposition of this matrix (only for square matrices).
-
getRowSums
public ComplexMatrix getRowSums()
Description copied from interface:MatrixReturns a column matrix of the sums of each row in this matrix.- Specified by:
getRowSumsin interfaceMatrix<org.apache.commons.math.complex.Complex>- Returns:
- Column matrix of sums
-
getColSums
public ComplexMatrix getColSums()
Description copied from interface:MatrixReturns a row matrix of the sums of each column in this matrix.- Specified by:
getColSumsin interfaceMatrix<org.apache.commons.math.complex.Complex>- Returns:
- Row matrix of sums
-
-