org.jscience.mathematics.algebraic
Class AbstractMatrix

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Member
Direct Known Subclasses:
AbstractComplexMatrix, AbstractDoubleMatrix, AbstractIntegerMatrix, AbstractSquareMatrix, AbstractVector, BooleanMatrix, RingMatrix

public abstract class AbstractMatrix
extends AbstractHypermatrix
implements Matrix, Algebra.Member, java.io.Serializable

The Matrix superclass provides an abstract encapsulation for traditional 2D matrices. Concrete implementations of this class should implement additional interfaces. See subclasses.

See Also:
Serialized Form

Constructor Summary
AbstractMatrix(int rows, int cols)
          Constructs a matrix.
 
Method Summary
 java.lang.Number getElement(int[] position)
          Returns the element at position given by the array of int.
protected static java.lang.String getInvalidElementMsg(int i, int j)
          Returns an "invalid element" error message.
 int numColumns()
          Returns the number of columns.
 int numRows()
          Returns the number of rows.
 void print(int w, int d)
          Print the matrix to stdout.
 void print(java.text.NumberFormat format, int width)
          Print the matrix to stdout.
 void print(java.io.PrintWriter output, int w, int d)
          Print the matrix to the output stream.
 void print(java.io.PrintWriter output, java.text.NumberFormat format, int width)
          Print the matrix to the output stream.
 java.lang.Object toArray()
          Converts an hypermatrix to an array of n dimensions
 java.lang.Number[][] toArray(Matrix v)
          Converts a matrix to an array.
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Matrix
getColumn, getElement, getRow, transpose
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from interface org.jscience.mathematics.algebraic.modules.VectorSpace.Member
scalarDivide
 
Methods inherited from interface org.jscience.mathematics.algebraic.modules.Module.Member
scalarMultiply
 
Methods inherited from interface org.jscience.mathematics.algebraic.groups.AbelianGroup.Member
add, negate, subtract
 
Methods inherited from interface org.jscience.mathematics.algebraic.fields.Ring.Member
multiply
 

Constructor Detail

AbstractMatrix

public AbstractMatrix(int rows,
                      int cols)
Constructs a matrix.

Method Detail

numRows

public final int numRows()
Returns the number of rows.

Specified by:
numRows in interface Matrix
Returns:
DOCUMENT ME!

numColumns

public final int numColumns()
Returns the number of columns.

Specified by:
numColumns in interface Matrix
Returns:
DOCUMENT ME!

getElement

public final java.lang.Number getElement(int[] position)
                                  throws IllegalDimensionException
Returns the element at position given by the array of int.

Specified by:
getElement in interface Hypermatrix
Specified by:
getElement in class AbstractHypermatrix
Parameters:
position - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

toArray

public java.lang.Object toArray()
Description copied from class: AbstractHypermatrix
Converts an hypermatrix to an array of n dimensions

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

toArray

public java.lang.Number[][] toArray(Matrix v)
Converts a matrix to an array.

Specified by:
toArray in interface Matrix
Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!

getInvalidElementMsg

protected static java.lang.String getInvalidElementMsg(int i,
                                                       int j)
Returns an "invalid element" error message.

Parameters:
i - row index of the element
j - column index of the element

print

public void print(int w,
                  int d)
Print the matrix to stdout. Line the elements up in columns with a Fortran-like 'Fw.d' style format.

Parameters:
w - Column width.
d - Number of digits after the decimal.

print

public void print(java.io.PrintWriter output,
                  int w,
                  int d)
Print the matrix to the output stream. Line the elements up in columns with a Fortran-like 'Fw.d' style format.

Parameters:
output - Output stream.
w - Column width.
d - Number of digits after the decimal.

print

public void print(java.text.NumberFormat format,
                  int width)
Print the matrix to stdout. Line the elements up in columns. Use the format object, and right justify within columns of width characters. Note that is the matrix is to be read back in, you probably will want to use a NumberFormat that is set to US Locale.

Parameters:
format - A Formatting object for individual elements.
width - Field width for each column.
See Also:
DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)

print

public void print(java.io.PrintWriter output,
                  java.text.NumberFormat format,
                  int width)
Print the matrix to the output stream. Line the elements up in columns. Use the format object, and right justify within columns of width characters. Note that is the matrix is to be read back in, you probably will want to use a NumberFormat that is set to US Locale.

Parameters:
output - the output stream.
format - A formatting object to format the matrix elements
width - Column width.
See Also:
DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)