org.jscience.mathematics.algebraic.matrices
Class ComplexMatrix

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
          extended by org.jscience.mathematics.algebraic.matrices.AbstractComplexMatrix
              extended by org.jscience.mathematics.algebraic.matrices.ComplexMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Member

public class ComplexMatrix
extends AbstractComplexMatrix
implements java.lang.Cloneable, java.io.Serializable

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.
 
Constructor Summary
ComplexMatrix(Complex[][] array)
          Constructs a matrix from an array.
ComplexMatrix(ComplexMatrix mat)
          Copy constructor.
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)
           
 java.lang.Object clone()
          Clone matrix into a new matrix.
 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.
 AbstractComplexVector getColumn(int j)
          Returns the ith column.
 double getImagElement(int i, int j)
          Returns the imag part of an element of the matrix.
 Complex getPrimitiveElement(int i, int j)
          Returns an element of the matrix.
 double getRealElement(int i, int j)
          Returns the real part of an element of the matrix.
 AbstractComplexVector getRow(int i)
          Returns the ith row.
 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 setAllElements(Complex m)
          Sets the value of all elements of the matrix.
 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 tensorProduct(AbstractComplexMatrix m)
          Returns the tensor product of this matrix and another.
 Complex[][] toPrimitiveArray()
          Projects the matrix to an array.
 java.lang.String toString()
          Returns a string representing this matrix.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractComplexMatrix
abs, add, equals, equals, getElement, getMatrixAsColumns, getMatrixAsRows, getSet, getSubMatrix, hashCode, horizontalAxisSymmetry, mass, multiply, read, reverse, scalarDivide, scalarMultiply, scalarProduct, setColumn, setRow, setSubMatrix, subtract, verticalAxisSymmetry
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractMatrix
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 

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

ComplexMatrix

public ComplexMatrix(ComplexMatrix mat)
Copy constructor.

Parameters:
mat - 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

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

getPrimitiveElement

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

Specified by:
getPrimitiveElement in class AbstractComplexMatrix
Parameters:
i - row index of the element
j - column index of the element
Throws:
IllegalDimensionException - 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.

Overrides:
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.

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

getRow

public AbstractComplexVector getRow(int i)
Returns the ith row.

Specified by:
getRow in interface Matrix
Overrides:
getRow in class AbstractComplexMatrix
Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!

getColumn

public AbstractComplexVector getColumn(int j)
Returns the ith column.

Specified by:
getColumn in interface Matrix
Overrides:
getColumn in class AbstractComplexMatrix
Parameters:
j - DOCUMENT ME!
Returns:
DOCUMENT ME!

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:
IllegalDimensionException - 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.

Overrides:
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:
IllegalDimensionException - If attempting to access an invalid element.

setAllElements

public void setAllElements(Complex m)
Sets the value of all elements of the matrix.

Overrides:
setAllElements in class AbstractComplexMatrix
Parameters:
m - a complex 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

negate

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

Specified by:
negate in interface AbelianGroup.Member
Overrides:
negate in class AbstractComplexMatrix
Returns:
DOCUMENT ME!

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:
IllegalDimensionException - 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:
IllegalDimensionException - 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:
IllegalDimensionException - 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:
IllegalDimensionException - 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

tensorProduct

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

Overrides:
tensorProduct 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.

Specified by:
transpose in interface 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

clone

public java.lang.Object clone()
Clone matrix into a new matrix.

Overrides:
clone in class java.lang.Object
Returns:
the cloned matrix.

toPrimitiveArray

public Complex[][] toPrimitiveArray()
Projects the matrix to an array.

Overrides:
toPrimitiveArray in class AbstractComplexMatrix
Returns:
an double array.