org.jscience.mathematics.algebraic.matrices
Class AbstractComplexMatrix

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
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Member
Direct Known Subclasses:
AbstractComplexSquareMatrix, ComplexMatrix, ComplexSparseMatrix

public abstract class AbstractComplexMatrix
extends AbstractMatrix

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

See Also:
Serialized Form

Constructor Summary
protected AbstractComplexMatrix(int rows, int cols)
          Constructs a matrix.
 
Method Summary
 AbstractDoubleMatrix abs()
          Applies the abs function on all the matrix components.
 AbelianGroup.Member add(AbelianGroup.Member m)
          Returns the addition of this matrix and another.
 AbstractComplexMatrix add(AbstractComplexMatrix m)
          Returns the addition of this matrix and another.
 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)
          Compares two complex matrices for equality.
 boolean equals(AbstractComplexMatrix m, double tol)
           
 boolean equals(java.lang.Object obj)
          Compares two complex matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius or Hilbert-Schmidt (l2) norm.
 AbstractComplexVector getColumn(int j)
          Returns the ith column.
 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.
 Complex[] getMatrixAsColumns()
          Make a one-dimensional column packed copy of the internal array.
 Complex[] getMatrixAsRows()
          Make a one-dimensional row packed copy of the internal array.
abstract  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.
 java.lang.Object getSet()
           
 AbstractComplexMatrix getSubMatrix(int k1, int k2, int k3, int k4)
          Computes a sub matrix from the parameters index.
 int hashCode()
          Returns a hashcode for this NON EMPTY matrix.
 AbstractComplexMatrix hermitianAdjoint()
          Returns the hermitian adjoint of this matrix.
 AbstractComplexMatrix horizontalAxisSymmetry()
          Invert matrix elements order from the top to the bottom.
 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.
 Complex mass()
          Gets the mass of the matrix components.
 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.
 Ring.Member multiply(Ring.Member m)
          Returns the multiplication of this matrix and another.
 AbelianGroup.Member negate()
          Returns the negative of this matrix.
static AbstractComplexMatrix read(java.io.BufferedReader input)
          Read a matrix from a stream.
 AbstractDoubleMatrix real()
          Returns the real part of this complex matrix.
 AbstractComplexMatrix reverse()
          Invert matrix elements order from the top to the bottom, from the right to the left.
 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.
 VectorSpace.Member scalarDivide(Field.Member 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.
 Module.Member scalarMultiply(Ring.Member x)
          Returns the multiplication of this matrix by a scalar.
 Complex scalarProduct(AbstractComplexMatrix m)
          Returns the scalar product of this matrix and another.
 void setAllElements(Complex m)
          Sets the value of all elements of the matrix.
 void setColumn(int j, AbstractComplexVector v)
          Returns the ith column.
abstract  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.
 void setRow(int i, AbstractComplexVector v)
          Returns the ith row.
 AbstractComplexMatrix setSubMatrix(int k, int l, AbstractComplexMatrix m)
          Set a sub matrix.
 AbelianGroup.Member subtract(AbelianGroup.Member m)
          Returns the subtraction of this matrix by another.
 AbstractComplexMatrix subtract(AbstractComplexMatrix m)
          Returns the subtraction of this matrix by another.
 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.
 AbstractComplexMatrix verticalAxisSymmetry()
          Invert matrix elements order from the right to the left.
 
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 

Constructor Detail

AbstractComplexMatrix

protected AbstractComplexMatrix(int rows,
                                int cols)
Constructs a matrix.

Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares two complex matrices for equality.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a complex matrix

equals

public boolean equals(AbstractComplexMatrix m)
Compares two complex matrices for equality. Two matrices are considered to be equal if the Frobenius norm of their difference is within the zero tolerance.

Parameters:
m - a complex matrix

equals

public boolean equals(AbstractComplexMatrix m,
                      double tol)

toString

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

Overrides:
toString in class java.lang.Object

hashCode

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

Overrides:
hashCode in class java.lang.Object

real

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

Returns:
a double matrix

imag

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

Returns:
a double matrix

getPrimitiveElement

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

Parameters:
i - row index of the element
j - column index of the element
Throws:
IllegalDimensionException - If attempting to access an invalid element.

getElement

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

Parameters:
i - row index of the element
j - column index of the element
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If attempting to access an invalid element.

getRealElement

public double getRealElement(int i,
                             int j)
Returns the real part of an element of the matrix.

Parameters:
i - row index of the element
j - column index of the element
Throws:
IllegalDimensionException - If attempting to access an invalid element.

getImagElement

public double getImagElement(int i,
                             int j)
Returns the imag part of an element of the matrix.

Parameters:
i - row index of the element
j - column index of the element
Throws:
IllegalDimensionException - If attempting to access an invalid element.

getRow

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

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!

getColumn

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

Parameters:
j - DOCUMENT ME!
Returns:
DOCUMENT ME!

setRow

public void setRow(int i,
                   AbstractComplexVector v)
Returns the ith row.


setColumn

public void setColumn(int j,
                      AbstractComplexVector v)
Returns the ith column.


setElement

public abstract 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.

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.

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.

Parameters:
m - a complex element

getSet

public final java.lang.Object getSet()

infNorm

public double infNorm()
Returns the linfinity-norm.


frobeniusNorm

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


abs

public AbstractDoubleMatrix abs()
Applies the abs function on all the matrix components.


mass

public Complex mass()
Gets the mass of the matrix components.

Returns:
the mass.

negate

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

Returns:
DOCUMENT ME!

add

public final AbelianGroup.Member add(AbelianGroup.Member m)
Returns the addition of this matrix and another.

Parameters:
m - a group member
Returns:
DOCUMENT ME!

add

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

Parameters:
m - a complex matrix
Throws:
IllegalDimensionException - If the matrices are different sizes.

subtract

public final AbelianGroup.Member subtract(AbelianGroup.Member m)
Returns the subtraction of this matrix by another.

Parameters:
m - a group member
Returns:
DOCUMENT ME!

subtract

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

Parameters:
m - a complex matrix
Throws:
IllegalDimensionException - If the matrices are different sizes.

scalarMultiply

public final Module.Member scalarMultiply(Ring.Member x)
Returns the multiplication of this matrix by a scalar.

Parameters:
x - a ring member
Returns:
DOCUMENT ME!

scalarMultiply

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

Parameters:
z - a complex number
Returns:
a complex matrix

scalarMultiply

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

Parameters:
x - a double
Returns:
a complex matrix

scalarDivide

public final VectorSpace.Member scalarDivide(Field.Member x)
Returns the division of this matrix by a scalar.

Parameters:
x - a field member
Returns:
DOCUMENT ME!

scalarDivide

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

Parameters:
z - a complex number
Returns:
a complex matrix

scalarDivide

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

Parameters:
x - a double
Returns:
a complex matrix

scalarProduct

public Complex scalarProduct(AbstractComplexMatrix m)
Returns the scalar product of this matrix and another.

Parameters:
m - a complex matrix.
Throws:
IllegalDimensionException - If the matrices are different sizes.

multiply

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

Parameters:
v - a complex vector
Throws:
IllegalDimensionException - If the matrix and vector are incompatible.

multiply

public final Ring.Member multiply(Ring.Member m)
Returns the multiplication of this matrix and another.

Parameters:
m - a ring member
Returns:
DOCUMENT ME!

multiply

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

Parameters:
m - a complex matrix
Returns:
an AbstractComplexMatrix or an AbstractComplexSquareMatrix as appropriate
Throws:
IllegalDimensionException - If the matrices are incompatible.

directSum

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


tensorProduct

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


hermitianAdjoint

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

Returns:
a complex matrix

conjugate

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

Returns:
a complex matrix

transpose

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

Returns:
a complex matrix

horizontalAxisSymmetry

public AbstractComplexMatrix horizontalAxisSymmetry()
Invert matrix elements order from the top to the bottom.


verticalAxisSymmetry

public AbstractComplexMatrix verticalAxisSymmetry()
Invert matrix elements order from the right to the left.


reverse

public AbstractComplexMatrix reverse()
Invert matrix elements order from the top to the bottom, from the right to the left.


getSubMatrix

public AbstractComplexMatrix getSubMatrix(int k1,
                                          int k2,
                                          int k3,
                                          int k4)
Computes a sub matrix from the parameters index. If k1<0 k1 elements are added at the beginning of the returned matrix If k2>numRows() k2-numRows() elements are added at the end of the returned matrix Finally, if k1>k2 the vector is returned inverted. If k3<0 k3 elements are added at the beginning of the returned matrix If k4>numColumns() k2-numColumns() elements are added at the end of the returned matrix Finally, if k3>k4 the matrix is returned inverted.

Parameters:
k1 - the beginning rows index
k2 - the finishing rows index
k3 - the beginning columns index
k4 - the finishing columns index
Returns:
the sub matrix.

setSubMatrix

public AbstractComplexMatrix setSubMatrix(int k,
                                          int l,
                                          AbstractComplexMatrix m)
Set a sub matrix. If k<0 k elements are added at the beginning of the returned matrix If k+v.numRows()>numRows() k+v.numRows()-numRows() elements are added at the end of the returned matrix If l<0 l elements are added at the beginning of the returned matrix If l+v.numColumns()>numColumns() l+v.numColumns()-numColumns() elements are added at the end of the returned matrix

Parameters:
k - Initial row index to offset the patching matrix
l - Initial column index to offset the patching matrix
m - the patching matrix

mapElements

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

Parameters:
f - a user-defined function
Returns:
a complex matrix

toPrimitiveArray

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

Returns:
an Complex array.

getMatrixAsRows

public Complex[] getMatrixAsRows()
Make a one-dimensional row packed copy of the internal array. Useful to iterate over the elements with an org.jscience.util.ArrayIterator

Returns:
Matrix elements packed in a one-dimensional array by rows.

getMatrixAsColumns

public Complex[] getMatrixAsColumns()
Make a one-dimensional column packed copy of the internal array. Useful to iterate over the elements with an org.jscience.util.ArrayIterator

Returns:
Matrix elements packed in a one-dimensional array by columns.

read

public static AbstractComplexMatrix read(java.io.BufferedReader input)
                                  throws java.io.IOException
Read a matrix from a stream. The format is the same the print method, so printed matrices can be read back in (provided they were printed using US Locale). Elements are separated by whitespace, all the elements for each row appear on a single line, the last row is followed by a blank line.

Parameters:
input - the input stream.
Throws:
java.io.IOException