Class ComplexMatrix
-
- All Implemented Interfaces:
public class ComplexMatrixA 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 ComplexMatrixconcatRows(ComplexMatrix top, ComplexMatrix bottom, ComplexMatrix out)Concatenates two complex matrices vertically (row-wise). static ComplexMatrixextractRows(ComplexMatrix A, int row0, int row1, ComplexMatrix out)Extracts a range of rows from a complex matrix. ComplexMatrixcopy()Creates a deep copy of this complex matrix. Complexdet()Computes the determinant of this complex matrix using LU decomposition. Complexget(int i, int j)Gets the complex element at the specified position. Complexget(int idx)Gets the complex element at the specified linear index. intgetNumCols()Returns the number of columns in this complex matrix. intgetNumElements()Returns the total number of elements in this complex matrix. intgetNumRows()Returns the number of rows in this complex matrix. booleanisEmpty()Checks if this complex matrix is empty (both real and imaginary parts have no elements). voidscale(double a)Scales this complex matrix by a real scalar value. voidset(int i, int j, Complex val)Sets the element at the specified position to a complex value. voidset(int row, int col, int val)Sets the element at the specified position to an integer value (real part only). voidset(int i, int j, double val)Sets the element at the specified position to a real value (imaginary part becomes zero). voidset(int idx, Complex val)Sets the element at the specified linear index to a complex value. ComplexMatrixsumRows()Computes the sum of each row, returning a complex matrix with one column. voidzero()Sets all elements of this complex matrix to zero (both real and imaginary parts). static ComplexMatrixeye(int n)Creates a complex identity matrix of the specified size. static ComplexMatrixzeros(int rows, int cols)Creates a complex zero matrix of the specified dimensions. ComplexMatrixmult(ComplexMatrix other)Multiplies this complex matrix by another complex matrix. ComplexMatrixadd(ComplexMatrix other)Adds another complex matrix to this one, returning a new matrix. ComplexMatrixsub(ComplexMatrix other)Subtracts another complex matrix from this one, returning a new matrix. ComplexMatrixtranspose()Returns the transpose of this complex matrix. ComplexMatrixconjugateTranspose()Returns the conjugate transpose (Hermitian transpose) of this complex matrix. ComplexMatrixscaleComplex(Complex z)Scales this complex matrix by a complex scalar, returning a new matrix. ComplexMatrixleftMatrixDivide(ComplexMatrix b)Solves the complex linear system A*x = b. FieldMatrix<Complex>toFieldMatrix()Converts this ComplexMatrix to an Apache Commons Math3 FieldMatrix. -
-
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).
-
eye
static ComplexMatrix eye(int n)
Creates a complex identity matrix of the specified size.
- Parameters:
n- the size of the identity matrix- Returns:
an n x n complex identity matrix
-
zeros
static ComplexMatrix zeros(int rows, int cols)
Creates a complex zero matrix of the specified dimensions.
- Parameters:
rows- the number of rowscols- the number of columns- Returns:
a rows x cols complex zero matrix
-
mult
ComplexMatrix mult(ComplexMatrix other)
Multiplies this complex matrix by another complex matrix. (A+iB)(C+iD) = (AC-BD) + i(AD+BC)
- Parameters:
other- the matrix to multiply by- Returns:
the product of the two complex matrices
-
add
ComplexMatrix add(ComplexMatrix other)
Adds another complex matrix to this one, returning a new matrix.
- Parameters:
other- the matrix to add- Returns:
a new ComplexMatrix that is the sum of this and other
-
sub
ComplexMatrix sub(ComplexMatrix other)
Subtracts another complex matrix from this one, returning a new matrix.
- Parameters:
other- the matrix to subtract- Returns:
a new ComplexMatrix that is this minus other
-
transpose
ComplexMatrix transpose()
Returns the transpose of this complex matrix.
- Returns:
the transpose
-
conjugateTranspose
ComplexMatrix conjugateTranspose()
Returns the conjugate transpose (Hermitian transpose) of this complex matrix. For (A+iB), the conjugate transpose is (A^T - iB^T).
- Returns:
the conjugate transpose
-
scaleComplex
ComplexMatrix scaleComplex(Complex z)
Scales this complex matrix by a complex scalar, returning a new matrix. (a+ib)(C+iD) = (aC-bD) + i(aD+bC)
- Parameters:
z- the complex scalar- Returns:
a new ComplexMatrix scaled by z
-
leftMatrixDivide
ComplexMatrix leftMatrixDivide(ComplexMatrix b)
Solves the complex linear system A*x = b. For square systems, uses LU decomposition. For overdetermined systems (more rows than columns), uses the real-embedding approach with SVD-based pseudo-inverse, which correctly handles rank-deficient systems.
The complex system (A_r + i*A_i)(x_r + i*x_i) = (b_r + i*b_i) is converted to the equivalent real system:
This 2m x 2n real system is solved via the real Matrix.leftMatrixDivide (SVD-based).[A_r, -A_i] [x_r] [b_r] [A_i, A_r] [x_i] = [b_i]- Parameters:
b- the right-hand side complex column vector or matrix- Returns:
the solution vector x
-
toFieldMatrix
FieldMatrix<Complex> toFieldMatrix()
Converts this ComplexMatrix to an Apache Commons Math3 FieldMatrix.
- Returns:
the equivalent FieldMatrix
-
-
-
-