Package com.imsl.math
Class ComplexSparseMatrix
java.lang.Object
com.imsl.math.ComplexSparseMatrix
- All Implemented Interfaces:
Serializable
Sparse matrix of type
Complex.
The class represents a general complex sparse matrix.
It is intended to be efficiently and easily updated.
A ComplexSparseMatrix can be constructed from a set of arrays, or it can
be abstractly created as an empty array and then incrementally built into final form.
It is usually easier to create an empty ComplexSparseMatrix of set size
and then use the set method to set the elements of the array. When
setting the elements of the sparse array, their positions should be thought of
as their positions in the dense array. Elements can be set in any order, but
only the elements set are stored.
This class includes methods to update the sparse matrix.
There are also methods to multiply a sparse matrix and a vector
or to multiply two sparse matrices.
To solve a sparse linear system use ComplexSparseCholesky
or ComplexSuperLU.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTheSparseArrayclass uses public fields to hold the data for a sparse matrix in the Java Sparse Array format. -
Constructor Summary
ConstructorsConstructorDescriptionComplexSparseMatrix(int nRows, int nColumns) Creates a new instance ofComplexSparseMatrix.ComplexSparseMatrix(int nRows, int nColumns, int[][] index, Complex[][] values) Constructs a sparse matrix from SparseArray (Java Sparse Array) data.Creates a new instance ofComplexSparseMatrixwhich is a copy of anotherComplexSparseMatrix.ComplexSparseMatrix(ComplexSparseMatrix.SparseArray sparseArray) Constructs a complex sparse matrix from aSparseArrayobject. -
Method Summary
Modifier and TypeMethodDescriptionstatic ComplexSparseMatrixadd(Complex alpha, Complex beta, ComplexSparseMatrix A, ComplexSparseMatrix B) Performs element-wise addition of two complex sparse matricesA,Bof typeComplexSparseMatrix, \(C \leftarrow \alpha A + \beta B.\)voidCheck that the matrix is square.Returns the conjugate transpose of the matrix.doubleReturns the Frobenius norm of the matrix.get(int iRow, int jColumn) Returns the value of an element in the matrix.intReturns the number of columns in the matrix.longReturns the number of nonzeros in the matrix.intReturns the number of rows in the matrix.doubleReturns the infinity norm of the matrix.Complex[]Multiply the matrix by a vector.static Complex[]multiply(Complex[] x, ComplexSparseMatrix A) Multiply row arrayxand sparse matrixA, \(x^TA \).static Complex[]multiply(ComplexSparseMatrix A, Complex[] x) Multiply sparse matrixAand column arrayx, \(A x\).static ComplexSparseMatrixMultiply two sparse complex matrices A and B, \( C \leftarrow AB\).static Complex[]Multiply sparse Hermitian matrixAand column vectorx.doubleoneNorm()Returns the matrix one norm of the sparse matrix.plusEquals(int iRow, int jColumn, Complex x) Adds a value to an element in the matrix.voidSets the value of an element in the matrix.Complex[][]Returns the sparse matrix as a dense matrix.Returns the sparse matrix in theSparseArrayform.
-
Constructor Details
-
ComplexSparseMatrix
public ComplexSparseMatrix(int nRows, int nColumns) Creates a new instance ofComplexSparseMatrix. Initially this is the zero matrix.- Parameters:
nRows- anintcontaining the number of rows in the sparse matrix.nColumns- anintcontaining the number of columns in the sparse matrix.
-
ComplexSparseMatrix
Creates a new instance ofComplexSparseMatrixwhich is a copy of anotherComplexSparseMatrix.- Parameters:
A- is theComplexSparseMatrixto be copied.
-
ComplexSparseMatrix
Constructs a complex sparse matrix from aSparseArrayobject.- Parameters:
sparseArray- is aSparseArrayused to initialize the sparse matrix. The fieldnumberOfNonZerosinSparseArrayis not used for initialization, so it does not have to be set.
-
ComplexSparseMatrix
Constructs a sparse matrix from SparseArray (Java Sparse Array) data.- Parameters:
nRows- anintcontaining the number of rows in the sparse matrix.nColumns- anintcontaining the number of columns in the sparse matrix.index- anintjagged array containing the column indices of all nonzero elements corresponding to the compressed representation of the sparse matrix invalues. The size ofindexmust be identical to the size ofvalues. The i-th row contains the column indices of all nonzero elements of row i of the sparse matrix. The j-th element of row i is the column index of the value located at the same position invalues.values- aComplexjagged array containing the compressed representation of a complex sparse matrix of sizenRowsbynColumns. The number of rows invaluesmust benRows. The i-th row contains all nonzero elements of row i of the full sparse matrix.
-
-
Method Details
-
getNumberOfRows
public int getNumberOfRows()Returns the number of rows in the matrix.- Returns:
- an
intcontaining the number of rows in the matrix.
-
getNumberOfColumns
public int getNumberOfColumns()Returns the number of columns in the matrix.- Returns:
- an
intcontaining the number of columns in the matrix.
-
getNumberOfNonZeros
public long getNumberOfNonZeros()Returns the number of nonzeros in the matrix.- Returns:
- a
longcontaining the number of nonzeros in the matrix.
-
get
Returns the value of an element in the matrix.- Parameters:
iRow- anintcontaining the row index of the element.jColumn- anintcontaining the column index of the element.- Returns:
- a
Complexcontaining the value of theiRow-th andjColumn-th element. If the element was never set, its value is zero.
-
set
Sets the value of an element in the matrix.- Parameters:
iRow- anintcontaining the row index of the element.jColumn- anintcontaining the column index of the element.x- aComplexcontaining the value of theiRow-th andjColumn-th element.
-
plusEquals
Adds a value to an element in the matrix.- Parameters:
iRow- anintcontaining the row index of the element.jColumn- anintcontaining the column index of the element.x- aComplexcontaining the value to be added.- Returns:
- a
Complexcontaining the updated value of the element, which equals its old value plus x.
-
checkSquareMatrix
public void checkSquareMatrix()Check that the matrix is square.- Throws:
IllegalArgumentException- is thrown if the matrix is not square.
-
add
public static ComplexSparseMatrix add(Complex alpha, Complex beta, ComplexSparseMatrix A, ComplexSparseMatrix B) Performs element-wise addition of two complex sparse matricesA,Bof typeComplexSparseMatrix, \(C \leftarrow \alpha A + \beta B.\)- Parameters:
alpha- aComplexscalar.beta- aComplexscalar.A- aComplexSparseMatrixmatrix.B- aComplexSparseMatrixmatrix.- Returns:
- a
ComplexSparseMatrixmatrix representing the computed sum. - Throws:
IllegalArgumentException- This exception is thrown if the matrices are not of the same size.
-
multiply
Multiply the matrix by a vector.- Parameters:
x- aComplexcolumn array.- Returns:
- a
Complexvector representing the product of this matrix times x. - Throws:
IllegalArgumentException- This exception is thrown if the number of columns in theComplexSparseMatrixobject is not equal to the number of elements in the input column vector.
-
multiply
Multiply sparse matrixAand column arrayx, \(A x\).- Parameters:
A- aComplexSparseMatrixmatrix.x- aComplexcolumn array.- Returns:
- a
Complexvector representing the product of the arguments, \(A x\). - Throws:
IllegalArgumentException- This exception is thrown when the number of columns in the input matrix is not equal to the number of elements in the input column vector.
-
multiply
Multiply row arrayxand sparse matrixA, \(x^TA \).- Parameters:
x- aComplexrow array.A- aComplexSparseMatrixmatrix.- Returns:
- a
Complexvector representing the product of the arguments, \( x^T A \). - Throws:
IllegalArgumentException- This exception is thrown when the number of elements in the input vector is not equal to the number of rows of the matrix.
-
multiplyHermitian
Multiply sparse Hermitian matrixAand column vectorx.- Parameters:
A- aComplexSparseMatrixsparse Hermitian matrix, where only the lower triangular part of the matrix is to be used.x- AComplexvector.- Returns:
- a
Complexvector representing the product of the arguments, \(Ax\). - Throws:
IllegalArgumentException- This exception is thrown when the input matrix is not square or the number of columns in the input matrix is not equal to the number of elements in the input column vector.
-
multiply
Multiply two sparse complex matrices A and B, \( C \leftarrow AB\).- Parameters:
A- aComplexSparseMatrixsparse matrix.B- aComplexSparseMatrixsparse matrix.- Returns:
- the
ComplexSparseMatrixproduct AB of A and B. - Throws:
IllegalArgumentException- This exception is thrown when the column number of matrix A is not equal to the row number of matrix B.
-
conjugateTranspose
Returns the conjugate transpose of the matrix.- Returns:
- a
ComplexSparseMatrixobject which is the conjugate transpose of the constructedComplexSparseMatrixobject.
-
oneNorm
public double oneNorm()Returns the matrix one norm of the sparse matrix.- Returns:
- a
doublevalue equal to the maximum of the column sums of the absolute values of the array elements.
-
infinityNorm
public double infinityNorm()Returns the infinity norm of the matrix.- Returns:
- a
doublescalar value equal to the maximum of the row sums of the absolute values of the array elements of the sparse matrix.
-
frobeniusNorm
public double frobeniusNorm()Returns the Frobenius norm of the matrix.- Returns:
- a
doublescalar value equal to the Frobenius norm of the matrix.
-
toDenseMatrix
Returns the sparse matrix as a dense matrix.- Returns:
- a rectangular Java array of type
Complexcontaining this matrix with all of the zeros explicitly present. The number of rows and columns in the returned matrix is the same as in the sparse matrix.
-
toSparseArray
Returns the sparse matrix in theSparseArrayform.
-