org.jscience.mathematics.algebraic.matrices
Class AbstractDoubleMatrix

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
          extended by org.jscience.mathematics.algebraic.matrices.AbstractDoubleMatrix
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Member
Direct Known Subclasses:
AbstractDoubleSquareMatrix, DoubleMatrix, DoubleSparseMatrix

public abstract class AbstractDoubleMatrix
extends AbstractMatrix

Set a submatrix.

See Also:
Serialized Form

Constructor Summary
protected AbstractDoubleMatrix(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.
 AbstractDoubleMatrix add(AbstractDoubleMatrix m)
          Returns the addition of this matrix and another.
 AbstractDoubleMatrix directSum(AbstractDoubleMatrix m)
          Returns the direct sum of this matrix and another.
 boolean equals(AbstractDoubleMatrix m)
          Compares two ${nativeTyp} matrices for equality.
 boolean equals(AbstractDoubleMatrix m, double tol)
           
 boolean equals(java.lang.Object obj)
          Compares two ${nativeTyp} matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius or Hilbert-Schmidt (l2) norm.
 AbstractDoubleVector getColumn(int j)
          Returns the ith column.
 Double getElement(int i, int j)
          Returns an element of the matrix.
 double[] getMatrixAsColumns()
          Make a one-dimensional column packed copy of the internal array.
 double[] getMatrixAsRows()
          Make a one-dimensional row packed copy of the internal array.
abstract  double getPrimitiveElement(int i, int j)
          Returns an element of the matrix.
 AbstractDoubleVector getRow(int i)
          Returns the ith row.
 java.lang.Object getSet()
           
 AbstractDoubleMatrix 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.
 AbstractDoubleMatrix horizontalAxisSymmetry()
          Invert matrix elements order from the top to the bottom.
 double infNorm()
          Returns the linfinity-norm.
 AbstractDoubleMatrix mapElements(PrimitiveMapping f)
          Applies a function on all the matrix elements.
 double mass()
          Gets the mass of the matrix components.
 double max()
          Gets the max of the matrix components.
 double mean()
          Gets the mean of the matrix components.
 double min()
          Gets the min of the matrix components.
 AbstractDoubleMatrix multiply(AbstractDoubleMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractDoubleVector multiply(AbstractDoubleVector 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 AbstractDoubleMatrix read(java.io.BufferedReader input)
          Read a matrix from a stream.
 AbstractDoubleMatrix reverse()
          Invert matrix elements order from the top to the bottom, from the right to the left.
 AbstractDoubleMatrix 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.
 AbstractDoubleMatrix 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.
 double scalarProduct(AbstractDoubleMatrix m)
          Returns the scalar product of this matrix and another.
 void setAllElements(double m)
          Sets the value of all elements of the matrix.
 void setColumn(int j, AbstractDoubleVector v)
          Returns the ith column.
abstract  void setElement(int i, int j, double x)
          Sets the value of an element of the matrix.
 void setRow(int i, AbstractDoubleVector v)
          Returns the ith row.
 AbstractDoubleMatrix setSubMatrix(int k, int l, AbstractDoubleMatrix m)
          Set a sub matrix.
 AbelianGroup.Member subtract(AbelianGroup.Member m)
          Returns the subtraction of this matrix by another.
 AbstractDoubleMatrix subtract(AbstractDoubleMatrix m)
          Returns the subtraction of this matrix by another.
 AbstractDoubleMatrix tensorProduct(AbstractDoubleMatrix m)
          Returns the tensor product of this matrix and another.
 AbstractComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 AbstractIntegerMatrix toIntegerMatrix()
          Converts this matrix to an integer matrix.
 double[][] 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.
 AbstractDoubleMatrix 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

AbstractDoubleMatrix

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

Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares two ${nativeTyp} matrices for equality.

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

equals

public boolean equals(AbstractDoubleMatrix m)
Compares two ${nativeTyp} 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 double matrix

equals

public boolean equals(AbstractDoubleMatrix 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

toIntegerMatrix

public AbstractIntegerMatrix toIntegerMatrix()
Converts this matrix to an integer matrix.

Returns:
an integer matrix

toComplexMatrix

public AbstractComplexMatrix toComplexMatrix()
Converts this matrix to a complex matrix.

Returns:
a complex matrix

getPrimitiveElement

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

getRow

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

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

getColumn

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

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

setRow

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


setColumn

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


setElement

public abstract void setElement(int i,
                                int j,
                                double x)
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 - a number
Throws:
IllegalDimensionException - If attempting to access an invalid element.

setAllElements

public void setAllElements(double 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.


min

public double min()
Gets the min of the matrix components.

Returns:
the min.

mass

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

Returns:
the mass.

max

public double max()
Gets the max of the matrix components.

Returns:
the max.

mean

public double mean()
Gets the mean of the matrix components.

Returns:
the mean.

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 AbstractDoubleMatrix add(AbstractDoubleMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a double 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 AbstractDoubleMatrix subtract(AbstractDoubleMatrix m)
Returns the subtraction of this matrix by another.

Parameters:
m - a double 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 AbstractDoubleMatrix scalarMultiply(double x)
Returns the multiplication of this matrix by a scalar.

Parameters:
x - a double.
Returns:
a double matrix.

scalarDivide

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

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

scalarDivide

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

Parameters:
x - a double.
Returns:
a double matrix.

scalarProduct

public double scalarProduct(AbstractDoubleMatrix m)
Returns the scalar product of this matrix and another.

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

multiply

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

Parameters:
v - a double 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 AbstractDoubleMatrix multiply(AbstractDoubleMatrix m)
Returns the multiplication of this matrix and another.

Parameters:
m - a double matrix
Returns:
a AbstractDoubleMatrix or a AbstractDoubleSquareMatrix as appropriate
Throws:
IllegalDimensionException - If the matrices are incompatible.

directSum

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


tensorProduct

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


transpose

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

Returns:
a double matrix

horizontalAxisSymmetry

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


verticalAxisSymmetry

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


reverse

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


getSubMatrix

public AbstractDoubleMatrix 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 AbstractDoubleMatrix setSubMatrix(int k,
                                         int l,
                                         AbstractDoubleMatrix 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 AbstractDoubleMatrix mapElements(PrimitiveMapping f)
Applies a function on all the matrix elements.

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

toPrimitiveArray

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

Returns:
an double array.

getMatrixAsRows

public double[] 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 double[] 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 AbstractDoubleMatrix 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