org.jscience.mathematics.algebraic.matrices
Class RingMatrix

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

public class RingMatrix
extends AbstractMatrix
implements java.lang.Cloneable, java.io.Serializable

The RingMatrix class provides an object for encapsulating matrices over an arbitrary ring.

See Also:
Serialized Form

Constructor Summary
RingMatrix(int numRows, int numCols)
          Constructs an empty matrix.
RingMatrix(Ring.Member[][] array)
          Constructs a matrix by wrapping an array.
RingMatrix(RingMatrix mat)
          Copy constructor.
 
Method Summary
 AbelianGroup.Member add(AbelianGroup.Member m)
          Returns the addition of this matrix and another.
 RingMatrix add(RingMatrix m)
          Returns the addition of this matrix and another.
 java.lang.Object clone()
          Clone matrix into a new matrix.
 RingMatrix directSum(RingMatrix m)
          Returns the direct sum of this matrix and another.
 boolean equals(java.lang.Object m)
          Compares two matrices for equality.
 RingVector getColumn(int j)
          Returns the ith column.
 java.lang.Number getElement(int i, int j)
          Returns an element of the matrix.
 Ring.Member[][] getElements()
          Returns a projection of this matrix.
 Ring.Member getPrimitiveElement(int i, int j)
          Returns an element of the matrix (fastest method).
 RingVector getRow(int i)
          Returns the ith row.
 RingMatrix mapElements(NumberMapping f)
          Applies a function on all the matrix elements.
 Ring.Member multiply(Ring.Member m)
          Returns the multiplication of this matrix and another.
 RingMatrix multiply(RingMatrix m)
          Returns the multiplication of this matrix and another.
 AbelianGroup.Member negate()
          Returns the negative of this matrix.
 VectorSpace.Member scalarDivide(Field.Member x)
          Returns the division of this matrix by a scalar.
 Module.Member scalarMultiply(Ring.Member r)
          Returns the multiplication of this matrix by a scalar.
 void setAllElements(Ring.Member m)
          Sets the value of all elements of the matrix.
 void setColumn(int j, RingVector v)
          Sets the ith column.
 void setElement(int i, int j, Ring.Member r)
          Sets the value of an element of the matrix.
 void setRow(int i, RingVector v)
          Sets the ith row.
 AbelianGroup.Member subtract(AbelianGroup.Member m)
          Returns the subtraction of this matrix and another.
 RingMatrix subtract(RingMatrix m)
          Returns the subtraction of this matrix and another.
 RingMatrix tensorProduct(RingMatrix m)
          Returns the tensor product of this matrix and another.
 java.lang.Object toArray()
          Returns a flat projection of this matrix, given "row first".
 Ring.Member[][] 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.AbstractMatrix
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 

Constructor Detail

RingMatrix

public RingMatrix(int numRows,
                  int numCols)
Constructs an empty matrix.

Parameters:
numRows - the number of rows
numCols - the number of columns

RingMatrix

public RingMatrix(Ring.Member[][] array)
Constructs a matrix by wrapping an array.

Parameters:
array - an assigned value

RingMatrix

public RingMatrix(RingMatrix mat)
Copy constructor.

Parameters:
mat - an assigned value
Method Detail

equals

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

Overrides:
equals in class java.lang.Object
Parameters:
m - a matrix
Returns:
DOCUMENT ME!

toString

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

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!

getElements

public Ring.Member[][] getElements()
Returns a projection of this matrix.

Returns:
DOCUMENT ME!

toArray

public java.lang.Object toArray()
Returns a flat projection of this matrix, given "row first". Useful to iterate over all the matrix elements.

Specified by:
toArray in interface Hypermatrix
Overrides:
toArray in class AbstractMatrix
Returns:
DOCUMENT ME!

getElement

public java.lang.Number getElement(int i,
                                   int j)
Returns an element of the matrix.

Specified by:
getElement in interface Matrix
Parameters:
i - row index of the element
j - column index of the element
Returns:
DOCUMENT ME!

getPrimitiveElement

public Ring.Member getPrimitiveElement(int i,
                                       int j)
Returns an element of the matrix (fastest method).

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 RingVector getRow(int i)
Returns the ith row.

Specified by:
getRow in interface Matrix
Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

getColumn

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

Specified by:
getColumn in interface Matrix
Parameters:
j - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

setRow

public void setRow(int i,
                   RingVector v)
Sets the ith row.

Parameters:
i - DOCUMENT ME!
v - DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

setColumn

public void setColumn(int j,
                      RingVector v)
Sets the ith column.

Parameters:
j - DOCUMENT ME!
v - DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

setElement

public void setElement(int i,
                       int j,
                       Ring.Member r)
                throws IllegalDimensionException
Sets the value of an element of the matrix.

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

setAllElements

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

Parameters:
m - a ring element

negate

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

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

add

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

Specified by:
add in interface AbelianGroup.Member
Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

add

public RingMatrix add(RingMatrix m)
               throws IllegalDimensionException
Returns the addition of this matrix and another.

Parameters:
m - a matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

subtract

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

Specified by:
subtract in interface AbelianGroup.Member
Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

subtract

public RingMatrix subtract(RingMatrix m)
                    throws IllegalDimensionException
Returns the subtraction of this matrix and another.

Parameters:
m - a matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

scalarMultiply

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

Specified by:
scalarMultiply in interface Module.Member
Parameters:
r - a ring element.
Returns:
DOCUMENT ME!

scalarDivide

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

Specified by:
scalarDivide in interface VectorSpace.Member
Parameters:
x - a field element.
Returns:
DOCUMENT ME!

multiply

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

Specified by:
multiply in interface Ring.Member
Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

multiply

public RingMatrix multiply(RingMatrix m)
                    throws IllegalDimensionException
Returns the multiplication of this matrix and another.

Parameters:
m - a matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are incompatible.

directSum

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

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

tensorProduct

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

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

transpose

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

Specified by:
transpose in interface Matrix
Returns:
a matrix

mapElements

public RingMatrix mapElements(NumberMapping f)
Applies a function on all the matrix elements.

Parameters:
f - a user-defined function
Returns:
a Ring matrix
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

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 Ring.Member[][] toPrimitiveArray()
Projects the matrix to an array.

Returns:
an int array.