Class ComplexMatrix
-
- All Implemented Interfaces:
public class ComplexMatrix
A matrix class for handling complex-valued matrices using separate real and imaginary components.
ComplexMatrix provides a comprehensive implementation for complex matrix operations by storing the real and imaginary parts as separate Matrix objects. This approach allows for efficient manipulation of complex numbers in matrix computations while leveraging the existing Matrix infrastructure.
Key features:
- Separate storage of real and imaginary components
- Support for all standard complex matrix operations
- Integration with Apache Commons Math for complex number operations
- Efficient determinant calculation using LU decomposition
- Row and column extraction operations
- Since:
1.0
QORE Lab, Imperial College London
-
-
Constructor Summary
Constructors Constructor Description ComplexMatrix(int i, int j)
Creates a new complex matrix with the specified dimensions. ComplexMatrix(Matrix real, Matrix im)
Creates a complex matrix from separate real and imaginary component matrices. ComplexMatrix(DMatrixSparseCSC matrix_real, DMatrixSparseCSC matrix_im)
Creates a complex matrix from EJML sparse matrices representing real and imaginary components. ComplexMatrix(Matrix real)
Creates a complex matrix from a real matrix with zero imaginary component.
-
Method Summary
Modifier and Type Method Description static ComplexMatrix
concatRows(ComplexMatrix top, ComplexMatrix bottom, ComplexMatrix out)
Concatenates two complex matrices vertically (row-wise). static ComplexMatrix
extractRows(ComplexMatrix A, int row0, int row1, ComplexMatrix out)
Extracts a range of rows from a complex matrix. ComplexMatrix
copy()
Creates a deep copy of this complex matrix. Complex
det()
Computes the determinant of this complex matrix using LU decomposition. Complex
get(int i, int j)
Gets the complex element at the specified position. Complex
get(int idx)
Gets the complex element at the specified linear index. int
getNumCols()
Returns the number of columns in this complex matrix. int
getNumElements()
Returns the total number of elements in this complex matrix. int
getNumRows()
Returns the number of rows in this complex matrix. boolean
isEmpty()
Checks if this complex matrix is empty (both real and imaginary parts have no elements). void
scale(double a)
Scales this complex matrix by a real scalar value. void
set(int i, int j, Complex val)
Sets the element at the specified position to a complex value. void
set(int row, int col, int val)
Sets the element at the specified position to an integer value (real part only). void
set(int i, int j, double val)
Sets the element at the specified position to a real value (imaginary part becomes zero). void
set(int idx, Complex val)
Sets the element at the specified linear index to a complex value. ComplexMatrix
sumRows()
Computes the sum of each row, returning a complex matrix with one column. void
zero()
Sets all elements of this complex matrix to zero (both real and imaginary parts). -
-
Constructor Detail
-
ComplexMatrix
ComplexMatrix(int i, int j)
Creates a new complex matrix with the specified dimensions.- Parameters:
i
- the number of rowsj
- the number of columns
-
ComplexMatrix
ComplexMatrix(Matrix real, Matrix im)
Creates a complex matrix from separate real and imaginary component matrices.- Parameters:
real
- the real component matrixim
- the imaginary component matrix
-
ComplexMatrix
ComplexMatrix(DMatrixSparseCSC matrix_real, DMatrixSparseCSC matrix_im)
Creates a complex matrix from EJML sparse matrices representing real and imaginary components.- Parameters:
matrix_real
- the real component as DMatrixSparseCSCmatrix_im
- the imaginary component as DMatrixSparseCSC
-
ComplexMatrix
ComplexMatrix(Matrix real)
Creates a complex matrix from a real matrix with zero imaginary component.- Parameters:
real
- the real component matrix (imaginary part will be set to zero)
-
-
Method Detail
-
concatRows
static ComplexMatrix concatRows(ComplexMatrix top, ComplexMatrix bottom, ComplexMatrix out)
Concatenates two complex matrices vertically (row-wise).
- Parameters:
top
- the upper complex matrixbottom
- the lower complex matrixout
- the output matrix, or null to create a new one- Returns:
a complex matrix with the concatenated rows
-
extractRows
static ComplexMatrix extractRows(ComplexMatrix A, int row0, int row1, ComplexMatrix out)
Extracts a range of rows from a complex matrix.
- Parameters:
A
- the source complex matrixrow0
- the first row to extract (inclusive)row1
- the last row to extract (exclusive)out
- the output matrix, or null to create a new one- Returns:
a complex matrix containing the extracted rows
-
copy
ComplexMatrix copy()
Creates a deep copy of this complex matrix.
- Returns:
a new ComplexMatrix that is a copy of this instance
-
det
Complex det()
Computes the determinant of this complex matrix using LU decomposition.
- Returns:
the complex determinant of the matrix
-
get
Complex get(int i, int j)
Gets the complex element at the specified position.
- Parameters:
i
- the row indexj
- the column index- Returns:
the complex value at the specified position
-
get
Complex get(int idx)
Gets the complex element at the specified linear index.
- Parameters:
idx
- the linear index- Returns:
the complex value at the specified index
-
getNumCols
int getNumCols()
Returns the number of columns in this complex matrix.
- Returns:
the number of columns
-
getNumElements
int getNumElements()
Returns the total number of elements in this complex matrix.
- Returns:
the total number of elements (rows * columns)
-
getNumRows
int getNumRows()
Returns the number of rows in this complex matrix.
- Returns:
the number of rows
-
isEmpty
boolean isEmpty()
Checks if this complex matrix is empty (both real and imaginary parts have no elements).
- Returns:
true if the matrix is empty, false otherwise
-
scale
void scale(double a)
Scales this complex matrix by a real scalar value. Both real and imaginary components are multiplied by the scalar.
- Parameters:
a
- the scalar value to multiply by
-
set
void set(int i, int j, Complex val)
Sets the element at the specified position to a complex value.
- Parameters:
i
- the row indexj
- the column indexval
- the complex value to set
-
set
void set(int row, int col, int val)
Sets the element at the specified position to an integer value (real part only). Special handling for Integer.MAX_VALUE and Integer.MIN_VALUE as positive and negative infinity.
- Parameters:
row
- the row indexcol
- the column indexval
- the integer value to set
-
set
void set(int i, int j, double val)
Sets the element at the specified position to a real value (imaginary part becomes zero).
- Parameters:
i
- the row indexj
- the column indexval
- the real value to set
-
set
void set(int idx, Complex val)
Sets the element at the specified linear index to a complex value.
- Parameters:
idx
- the linear indexval
- the complex value to set
-
sumRows
ComplexMatrix sumRows()
Computes the sum of each row, returning a complex matrix with one column.
- Returns:
a complex matrix containing the row sums
-
zero
void zero()
Sets all elements of this complex matrix to zero (both real and imaginary parts).
-
-
-
-