SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.generic.matrixtype
Class GenericMatrix<F extends Field<F>>

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.generic.matrixtype.GenericMatrix<F>
Type Parameters:
F - the number Field
All Implemented Interfaces:
AbelianGroup<GenericMatrix<F>>, Monoid<GenericMatrix<F>>, Ring<GenericMatrix<F>>, VectorSpace<GenericMatrix<F>,F>, Matrix<GenericMatrix<F>,F>, MatrixAccessor<F>, MatrixDimension

public class GenericMatrix<F extends Field<F>>
extends java.lang.Object
implements Matrix<GenericMatrix<F>,F>

This class represents a generic Matrix of which the entries can be in any Field.


Constructor Summary
GenericMatrix(F[][] data)
          Create an instance of Matrix from a given 2D array.
GenericMatrix(int nRows, int nCols, F init)
          Create an instance of Matrix with nRows rows and nCols columns, initialized with value init.
 
Method Summary
 GenericMatrix<F> add(GenericMatrix<F> that)
          + : G × G → G
 boolean equals(java.lang.Object obj)
           
 F get(int row, int col)
          Get the matrix element at [row, col].
 int hashCode()
           
 GenericMatrix<F> minus(GenericMatrix<F> that)
          - : G × G → G - is not in the definition of of an additive group but can be deduced.
 GenericMatrix<F> multiply(GenericMatrix<F> that)
          · : G × G → G
 int nCols()
          Get the number of columns.
 int nRows()
          Get the number of rows.
 GenericMatrix<F> ONE()
          The multiplicative element 1 in the group such that for any elements a in the group, the equation 1 × a = a × 1 = a holds.
 GenericMatrix<F> opposite()
          For each a in G, there exists an element b in G such that a + b = b + a = 0 That is, it is the object such as this.add(this.opposite()) == this.ZERO
 GenericMatrix<F> scaled(F scalar)
          * : F × V → V The result of applying this function to scalar, c, in F and v in V is denoted cv.
 void set(int row, int col, F value)
          Set the matrix element at [row, col] to value.
 java.lang.String toString()
           
 GenericMatrix<F> ZERO()
          The additive element 0 in the group, such that for all elements a in the group, the equation 0 + a = a + 0 = a holds.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GenericMatrix

public GenericMatrix(int nRows,
                     int nCols,
                     F init)
Create an instance of Matrix with nRows rows and nCols columns, initialized with value init.

Parameters:
nRows - number of rows
nCols - number of columns
init - initial value for the entries

GenericMatrix

public GenericMatrix(F[][] data)
Create an instance of Matrix from a given 2D array.

Parameters:
data - the matrix entries
Method Detail

nRows

public int nRows()
Description copied from interface: MatrixDimension
Get the number of rows. Rows count from 1.

Specified by:
nRows in interface MatrixDimension
Returns:
the number of rows

nCols

public int nCols()
Description copied from interface: MatrixDimension
Get the number of columns. Columns count from 1.

Specified by:
nCols in interface MatrixDimension
Returns:
the number of columns

set

public void set(int row,
                int col,
                F value)
         throws MatrixAccessException
Description copied from interface: MatrixAccessor
Set the matrix element at [row, col] to value.

This is the only function that may change the entries of a matrix.

Specified by:
set in interface MatrixAccessor<F extends Field<F>>
Parameters:
row - the row index
col - the column index
value - the value to set A[row, col] to
Throws:
MatrixAccessException - if row or col is out of range

get

public F get(int row,
             int col)
                       throws MatrixAccessException
Description copied from interface: MatrixAccessor
Get the matrix element at [row, col].

Specified by:
get in interface MatrixAccessor<F extends Field<F>>
Parameters:
row - the row index
col - the column index
Returns:
A[row, col]
Throws:
MatrixAccessException - if row or col is out of range

add

public GenericMatrix<F> add(GenericMatrix<F> that)
Description copied from interface: AbelianGroup
+ : G × G → G

Specified by:
add in interface AbelianGroup<GenericMatrix<F extends Field<F>>>
Parameters:
that - the object to be added
Returns:
this + that

minus

public GenericMatrix<F> minus(GenericMatrix<F> that)
Description copied from interface: AbelianGroup
- : G × G → G

- is not in the definition of of an additive group but can be deduced. This function is provided for convenience purpose. It is equivalent to

this.add(that.opposite())

Specified by:
minus in interface AbelianGroup<GenericMatrix<F extends Field<F>>>
Parameters:
that - the object to be subtracted (subtrahend)
Returns:
this - that

multiply

public GenericMatrix<F> multiply(GenericMatrix<F> that)
Description copied from interface: Monoid
· : G × G → G

Specified by:
multiply in interface Monoid<GenericMatrix<F extends Field<F>>>
Parameters:
that - the multiplicand
Returns:
this × that

scaled

public GenericMatrix<F> scaled(F scalar)
Description copied from interface: VectorSpace
* : F × V → V

The result of applying this function to scalar, c, in F and v in V is denoted cv.

Specified by:
scaled in interface VectorSpace<GenericMatrix<F extends Field<F>>,F extends Field<F>>
Parameters:
scalar - a multiplier
Returns:
scalar * this
See Also:
Wikipedia: Scalar multiplication

opposite

public GenericMatrix<F> opposite()
Description copied from interface: AbelianGroup
For each a in G, there exists an element b in G such that
a + b = b + a = 0

That is, it is the object such as

this.add(this.opposite()) == this.ZERO

Specified by:
opposite in interface AbelianGroup<GenericMatrix<F extends Field<F>>>
Returns:
-this
See Also:
Wikipedia: Additive inverse

ZERO

public GenericMatrix<F> ZERO()
Description copied from interface: AbelianGroup
The additive element 0 in the group, such that for all elements a in the group, the equation
0 + a = a + 0 = a
holds.

Specified by:
ZERO in interface AbelianGroup<GenericMatrix<F extends Field<F>>>
Returns:
0

ONE

public GenericMatrix<F> ONE()
Description copied from interface: Monoid
The multiplicative element 1 in the group such that for any elements a in the group, the equation
1 × a = a × 1 = a
holds.

Specified by:
ONE in interface Monoid<GenericMatrix<F extends Field<F>>>
Returns:
1

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.