JSci.maths.matrices
Class ComplexMatrix

java.lang.Object
  extended by JSci.maths.matrices.Matrix
      extended by JSci.maths.matrices.AbstractComplexMatrix
          extended by JSci.maths.matrices.ComplexMatrix
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Module.Member, VectorSpace.Member, Ring.Member, AbelianGroup.Member, Member

public class ComplexMatrix
extends AbstractComplexMatrix

The ComplexMatrix class provides an object for encapsulating matrices containing complex numbers.

See Also:
Serialized Form

Field Summary
protected  double[][] matrixIm
          Arrays containing the elements of the matrix.
protected  double[][] matrixRe
          Arrays containing the elements of the matrix.
 
Fields inherited from class JSci.maths.matrices.Matrix
numCols, numRows
 
Constructor Summary
ComplexMatrix(Complex[][] array)
          Constructs a matrix from an array.
ComplexMatrix(ComplexVector[] array)
          Constructs a matrix from an array of vectors (columns).
ComplexMatrix(double[][] arrayRe, double[][] arrayIm)
          Constructs a matrix by wrapping two arrays.
ComplexMatrix(int rows, int cols)
          Constructs an empty matrix.
 
Method Summary
 AbstractComplexMatrix add(AbstractComplexMatrix m)
          Returns the addition of this matrix and another.
 ComplexMatrix add(ComplexMatrix m)
           
 AbstractComplexMatrix conjugate()
          Returns the complex conjugate of this matrix.
 AbstractComplexMatrix directSum(AbstractComplexMatrix m)
          Returns the direct sum of this matrix and another.
 boolean equals(AbstractComplexMatrix m, double tol)
          Compares two complex matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius or Hilbert-Schmidt (l2) norm.
 Complex getElement(int i, int j)
          Returns an element of the matrix.
 double getImagElement(int i, int j)
          Returns the imag part of an element of the matrix.
 double getRealElement(int i, int j)
          Returns the real part of an element of the matrix.
 int hashCode()
          Returns a hashcode for this matrix.
 AbstractComplexMatrix hermitianAdjoint()
          Returns the hermitian adjoint of this matrix.
 AbstractDoubleMatrix imag()
          Returns the imaginary part of this complex matrix.
 double infNorm()
          Returns the linfinity-norm.
 AbstractComplexMatrix mapElements(ComplexMapping f)
          Applies a function on all the matrix elements.
 AbstractComplexMatrix multiply(AbstractComplexMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractComplexVector multiply(AbstractComplexVector v)
          Returns the multiplication of a vector by this matrix.
 AbstractComplexMatrix multiply(ComplexMatrix m)
           
 AbelianGroup.Member negate()
          Returns the negative of this matrix.
 AbstractDoubleMatrix real()
          Returns the real part of this complex matrix.
 AbstractComplexMatrix scalarDivide(Complex z)
          Returns the division of this matrix by a scalar.
 AbstractComplexMatrix scalarDivide(double x)
          Returns the division of this matrix by a scalar.
 AbstractComplexMatrix scalarMultiply(Complex z)
          Returns the multiplication of this matrix by a scalar.
 AbstractComplexMatrix scalarMultiply(double x)
          Returns the multiplication of this matrix by a scalar.
 void setElement(int i, int j, Complex z)
          Sets the value of an element of the matrix.
 void setElement(int i, int j, double x, double y)
          Sets the value of an element of the matrix.
 AbstractComplexMatrix subtract(AbstractComplexMatrix m)
          Returns the subtraction of this matrix by another.
 ComplexMatrix subtract(ComplexMatrix m)
           
 AbstractComplexMatrix tensor(AbstractComplexMatrix m)
          Returns the tensor product of this matrix and another.
 java.lang.String toString()
          Returns a string representing this matrix.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class JSci.maths.matrices.AbstractComplexMatrix
add, equals, equals, getSet, multiply, scalarDivide, scalarMultiply, scalarProduct, subtract
 
Methods inherited from class JSci.maths.matrices.Matrix
columns, getInvalidElementMsg, rows
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

matrixRe

protected double[][] matrixRe
Arrays containing the elements of the matrix.


matrixIm

protected double[][] matrixIm
Arrays containing the elements of the matrix.

Constructor Detail

ComplexMatrix

public ComplexMatrix(int rows,
                     int cols)
Constructs an empty matrix.

Parameters:
rows - the number of rows
cols - the number of columns

ComplexMatrix

public ComplexMatrix(double[][] arrayRe,
                     double[][] arrayIm)
Constructs a matrix by wrapping two arrays.

Parameters:
arrayRe - an array of real values
arrayIm - an array of imaginary values

ComplexMatrix

public ComplexMatrix(Complex[][] array)
Constructs a matrix from an array.

Parameters:
array - an assigned value

ComplexMatrix

public ComplexMatrix(ComplexVector[] array)
Constructs a matrix from an array of vectors (columns).

Parameters:
array - an assigned value
Method Detail

equals

public boolean equals(AbstractComplexMatrix m,
                      double tol)
Compares two complex matrices for equality.

Overrides:
equals in class AbstractComplexMatrix
Parameters:
m - a complex matrix

toString

public java.lang.String toString()
Returns a string representing this matrix.

Overrides:
toString in class AbstractComplexMatrix

hashCode

public int hashCode()
Returns a hashcode for this matrix.

Overrides:
hashCode in class AbstractComplexMatrix

real

public AbstractDoubleMatrix real()
Returns the real part of this complex matrix.

Overrides:
real in class AbstractComplexMatrix
Returns:
a double matrix

imag

public AbstractDoubleMatrix imag()
Returns the imaginary part of this complex matrix.

Overrides:
imag in class AbstractComplexMatrix
Returns:
a double matrix

getElement

public Complex getElement(int i,
                          int j)
Returns an element of the matrix.

Specified by:
getElement in class AbstractComplexMatrix
Parameters:
i - row index of the element
j - column index of the element
Throws:
MatrixDimensionException - If attempting to access an invalid element.

getRealElement

public double getRealElement(int i,
                             int j)
Description copied from class: AbstractComplexMatrix
Returns the real part of an element of the matrix.

Specified by:
getRealElement in class AbstractComplexMatrix
Parameters:
i - row index of the element
j - column index of the element

getImagElement

public double getImagElement(int i,
                             int j)
Description copied from class: AbstractComplexMatrix
Returns the imag part of an element of the matrix.

Specified by:
getImagElement in class AbstractComplexMatrix
Parameters:
i - row index of the element
j - column index of the element

setElement

public void setElement(int i,
                       int j,
                       Complex z)
Sets the value of an element of the matrix. Should only be used to initialise this matrix.

Specified by:
setElement in class AbstractComplexMatrix
Parameters:
i - row index of the element
j - column index of the element
z - a complex number
Throws:
MatrixDimensionException - If attempting to access an invalid element.

setElement

public void setElement(int i,
                       int j,
                       double x,
                       double y)
Sets the value of an element of the matrix. Should only be used to initialise this matrix.

Specified by:
setElement in class AbstractComplexMatrix
Parameters:
i - row index of the element
j - column index of the element
x - the real part of a complex number
y - the imaginary part of a complex number
Throws:
MatrixDimensionException - If attempting to access an invalid element.

infNorm

public double infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class AbstractComplexMatrix

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius or Hilbert-Schmidt (l2) norm.

Overrides:
frobeniusNorm in class AbstractComplexMatrix
PlanetMath references:
FrobeniusMatrixNorm

negate

public AbelianGroup.Member negate()
Returns the negative of this matrix.

Specified by:
negate in interface AbelianGroup.Member
Overrides:
negate in class AbstractComplexMatrix

add

public AbstractComplexMatrix add(AbstractComplexMatrix m)
Returns the addition of this matrix and another.

Overrides:
add in class AbstractComplexMatrix
Parameters:
m - a complex matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

add

public ComplexMatrix add(ComplexMatrix m)

subtract

public AbstractComplexMatrix subtract(AbstractComplexMatrix m)
Returns the subtraction of this matrix by another.

Overrides:
subtract in class AbstractComplexMatrix
Parameters:
m - a complex matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

public ComplexMatrix subtract(ComplexMatrix m)

scalarMultiply

public AbstractComplexMatrix scalarMultiply(Complex z)
Returns the multiplication of this matrix by a scalar.

Overrides:
scalarMultiply in class AbstractComplexMatrix
Parameters:
z - a complex number
Returns:
a complex matrix

scalarMultiply

public AbstractComplexMatrix scalarMultiply(double x)
Returns the multiplication of this matrix by a scalar.

Overrides:
scalarMultiply in class AbstractComplexMatrix
Parameters:
x - a double
Returns:
a complex matrix

scalarDivide

public AbstractComplexMatrix scalarDivide(Complex z)
Returns the division of this matrix by a scalar.

Overrides:
scalarDivide in class AbstractComplexMatrix
Parameters:
z - a complex number
Returns:
a complex matrix

scalarDivide

public AbstractComplexMatrix scalarDivide(double x)
Returns the division of this matrix by a scalar.

Overrides:
scalarDivide in class AbstractComplexMatrix
Parameters:
x - a double
Returns:
a complex matrix

multiply

public AbstractComplexVector multiply(AbstractComplexVector v)
Returns the multiplication of a vector by this matrix.

Overrides:
multiply in class AbstractComplexMatrix
Parameters:
v - a complex vector
Throws:
DimensionException - If the matrix and vector are incompatible.

multiply

public AbstractComplexMatrix multiply(AbstractComplexMatrix m)
Returns the multiplication of this matrix and another.

Overrides:
multiply in class AbstractComplexMatrix
Parameters:
m - a complex matrix
Returns:
an AbstractComplexMatrix or an AbstractComplexSquareMatrix as appropriate
Throws:
MatrixDimensionException - If the matrices are incompatible.

multiply

public AbstractComplexMatrix multiply(ComplexMatrix m)

directSum

public AbstractComplexMatrix directSum(AbstractComplexMatrix m)
Returns the direct sum of this matrix and another.

Overrides:
directSum in class AbstractComplexMatrix

tensor

public AbstractComplexMatrix tensor(AbstractComplexMatrix m)
Returns the tensor product of this matrix and another.

Overrides:
tensor in class AbstractComplexMatrix

hermitianAdjoint

public AbstractComplexMatrix hermitianAdjoint()
Returns the hermitian adjoint of this matrix.

Overrides:
hermitianAdjoint in class AbstractComplexMatrix
Returns:
a complex matrix

conjugate

public AbstractComplexMatrix conjugate()
Returns the complex conjugate of this matrix.

Overrides:
conjugate in class AbstractComplexMatrix
Returns:
a complex matrix

transpose

public Matrix transpose()
Returns the transpose of this matrix.

Overrides:
transpose in class AbstractComplexMatrix
Returns:
a complex matrix

mapElements

public AbstractComplexMatrix mapElements(ComplexMapping f)
Applies a function on all the matrix elements.

Overrides:
mapElements in class AbstractComplexMatrix
Parameters:
f - a user-defined function
Returns:
a complex matrix