SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.generic.matrixtype
Class RealMatrix

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.generic.matrixtype.RealMatrix
All Implemented Interfaces:
AbelianGroup<RealMatrix>, Monoid<RealMatrix>, Ring<RealMatrix>, VectorSpace<RealMatrix,Real>, Matrix<RealMatrix,Real>, MatrixAccessor<Real>, MatrixDimension

public class RealMatrix
extends java.lang.Object
implements Matrix<RealMatrix,Real>

This class represents a matrix of Real numbers.

Comparing to the double-based DenseMatrix, this class allows arbitrary precision arithmetic at the cost of (much) slower performance.

For some high precision mathematics, we often do the calculation using more number of decimal points. We then cast back the results to double for higher accuracy.


Constructor Summary
RealMatrix(double[][] data)
          Construct a RealMatrix from a 2D array of doubles.
RealMatrix(int nRows, int nCols)
          Construct a nRows x nCols matrix of Real numbers.
RealMatrix(Real[][] data)
          Construct a matrix from a 2D array of Real numbers.
 
Method Summary
 RealMatrix add(RealMatrix that)
          + : G × G → G
 DenseMatrix doubleValue()
          Create a DenseMatrix of double values from this real matrix.
 boolean equals(java.lang.Object obj)
           
 Real get(int row, int col)
          Get the matrix element at [row, col].
 int hashCode()
           
 RealMatrix minus(RealMatrix that)
          - : G × G → G - is not in the definition of of an additive group but can be deduced.
 RealMatrix multiply(RealMatrix that)
          · : G × G → G
 int nCols()
          Get the number of columns.
 int nRows()
          Get the number of rows.
 RealMatrix 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.
 RealMatrix 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
 RealMatrix scaled(Real 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, Real value)
          Set the matrix element at [row, col] to value.
 java.lang.String toString()
           
 RealMatrix 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

RealMatrix

public RealMatrix(int nRows,
                  int nCols)
Construct a nRows x nCols matrix of Real numbers.

Parameters:
nRows - number of rows
nCols - number of columns

RealMatrix

public RealMatrix(Real[][] data)
Construct a matrix from a 2D array of Real numbers.

Parameters:
data - a matrix arrangement of Real numbers in a 2D array

RealMatrix

public RealMatrix(double[][] data)
Construct a RealMatrix from a 2D array of doubles.

Parameters:
data - a matrix arrangement of doubles in a 2D array
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,
                Real value)
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<Real>
Parameters:
row - the row index
col - the column index
value - the value to set A[row, col] to

get

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

Specified by:
get in interface MatrixAccessor<Real>
Parameters:
row - the row index
col - the column index
Returns:
A[row, col]

add

public RealMatrix add(RealMatrix that)
Description copied from interface: AbelianGroup
+ : G × G → G

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

minus

public RealMatrix minus(RealMatrix 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<RealMatrix>
Parameters:
that - the object to be subtracted (subtrahend)
Returns:
this - that

multiply

public RealMatrix multiply(RealMatrix that)
Description copied from interface: Monoid
· : G × G → G

Specified by:
multiply in interface Monoid<RealMatrix>
Parameters:
that - the multiplicand
Returns:
this × that

scaled

public RealMatrix scaled(Real 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<RealMatrix,Real>
Parameters:
scalar - a multiplier
Returns:
scalar * this
See Also:
Wikipedia: Scalar multiplication

opposite

public RealMatrix 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<RealMatrix>
Returns:
-this
See Also:
Wikipedia: Additive inverse

ZERO

public RealMatrix 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<RealMatrix>
Returns:
0

ONE

public RealMatrix 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<RealMatrix>
Returns:
1

doubleValue

public DenseMatrix doubleValue()
Create a DenseMatrix of double values from this real matrix.

Returns:
a double matrix of type DenseMatrix

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.