mpv2
Class SimpleMatrix

java.lang.Object
  extended by mpv2.AllMatrices
      extended by mpv2.SimpleMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class SimpleMatrix
extends AllMatrices
implements java.lang.Cloneable, java.io.Serializable

This is a simple matrix class made by implementing AllMatrices as simple as possible. Only som constructors, and get and set are added here.

Also added some more methods, getColum, setColumn, addColum, getRow and setRow. But this implementation is still simple.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class mpv2.AllMatrices
K, N
 
Constructor Summary
SimpleMatrix(AllMatrices B)
          Construct a new matrix from another matrix (of any kind) if argument B is an object of class SimpleMatrix this is the same as (deep) copy (or clone).
SimpleMatrix(double[][] A)
          Construct a matrix from a 2-D array, all values are copied.
SimpleMatrix(double[] vals, int n)
          Construct a matrix from a one-dimensional packed array
SimpleMatrix(int n, int k)
          Construct an m-by-n matrix of zeros.
SimpleMatrix(int n, int k, double s)
          Construct an m-by-n constant matrix.
 
Method Summary
 void addColumn(int k, double factor, double[] x)
          Add a column of the matrix multiplied by a factor to x, x = x + A[][k] Legal range of the integer argument is 0 <= k < K.
 java.lang.Object clone()
          Clone the Matrix object.
 SimpleMatrix copy()
          Make a deep copy of a matrix
 double get(int n, int k)
          Get a single element.
 void getColumn(int k, double[] d)
          Copy a column of the matrix into argument d Legal range of the integer argument is 0 <= k < K.
 void getRow(int n, double[] r)
          Copy a row of the matrix Legal range of the integer argument is 0 <= n < N.
 void set(int n, int k, double s)
          Set a single element.
 void setAll(double[] vals)
          Set all entries of to matrix to the supplied new values If argument is wrong length an IllegalArgumentException is thrown.
 void setColumn(int k, double[] d)
          Copy an array (d) into a column of the matrix Legal range of the integer argument is 0 <= k < K.
 void setRow(int n, double[] r)
          Set a row of the matrix Legal range of the integer argument is 0 <= n < N.
 double sumAll()
          Sum of all elements in matrix
 void timeseqScaleColumns(DiagonalMatrix D)
          Scale the columns of this, A *= D which is A = A * D.
 void timeseqScaleRows(DiagonalMatrix D)
          Scale the rows of this, A *= D which is A = D * A.
 
Methods inherited from class mpv2.AllMatrices
chol, columnNorm0, columnNorm1, columnNorm2, columnNormInf, cond, det, eig, eqConstant, eqCopy, eqCopy, eqCopy, eqCopy, eqCopy, eqDifference, eqEProduct, eqEQuotient, eqIdentity, eqInverse, eqIProduct, eqNegate, eqOnes, eqPermuteColumns, eqPermuteRows, eqProduct, eqProduct, eqRandom, eqScaleColumns, eqScaleRows, eqSum, eqTProduct, eqTranspose, eqZeros, getAll, getAll, getColumn, getColumnDimension, getK, getN, getRow, getRowDimension, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, getValue, innerProduct, lu, lup, norm1, norm2, normF, normInf, pluseqOuterProduct, print, print, print, print, qr, rank, setValue, svd, times, times, times, times, trace, transposeTimes, transposeTimes, transposeTimes, transposeTimes
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleMatrix

public SimpleMatrix(int n,
                    int k)
Construct an m-by-n matrix of zeros.

Parameters:
n - Number of rows.
k - Number of colums.

SimpleMatrix

public SimpleMatrix(int n,
                    int k,
                    double s)
Construct an m-by-n constant matrix.

Parameters:
n - Number of rows.
k - Number of colums.
s - Fill the matrix with this scalar value.

SimpleMatrix

public SimpleMatrix(double[][] A)
Construct a matrix from a 2-D array, all values are copied.

Parameters:
A - Two-dimensional array of doubles.
Throws:
java.lang.IllegalArgumentException - All rows must have the same length

SimpleMatrix

public SimpleMatrix(double[] vals,
                    int n)
Construct a matrix from a one-dimensional packed array

Parameters:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).
n - Number of rows, i.e. length of columns.
Throws:
java.lang.IllegalArgumentException - Array length must be a multiple of m.

SimpleMatrix

public SimpleMatrix(AllMatrices B)
Construct a new matrix from another matrix (of any kind) if argument B is an object of class SimpleMatrix this is the same as (deep) copy (or clone). Note that argument B may be another kind of matrix, ex. an object of class SparseMatrix or BandMatrix or any subclass of AllMatrices

Parameters:
B - a matrix of any kind, class is a subclass of AllMatrices
See Also:
copy()
Method Detail

copy

public SimpleMatrix copy()
Make a deep copy of a matrix


clone

public java.lang.Object clone()
Clone the Matrix object.

Overrides:
clone in class java.lang.Object

get

public double get(int n,
                  int k)
Get a single element.

Specified by:
get in class AllMatrices
Parameters:
n - Row index.
k - Column index.
Returns:
A(n,k)
Throws:
java.lang.ArrayIndexOutOfBoundsException

set

public void set(int n,
                int k,
                double s)
Set a single element.

Specified by:
set in class AllMatrices
Parameters:
n - Row index.
k - Column index.
s - A(n,k).
Throws:
java.lang.ArrayIndexOutOfBoundsException

getColumn

public void getColumn(int k,
                      double[] d)
Copy a column of the matrix into argument d Legal range of the integer argument is 0 <= k < K. If argument is out of range a length N array of zeros should be returned.
The corresponding Matlab expression would be: A(:,k+1).

Overrides:
getColumn in class AllMatrices
Parameters:
k - number of the column in the matrix
d - the given column of the matrix

setColumn

public void setColumn(int k,
                      double[] d)
Copy an array (d) into a column of the matrix Legal range of the integer argument is 0 <= k < K. If argument is out of range an IllegalArgumentException is thrown.
The corresponding Matlab expression would be: A(:,k+1) = d.

Overrides:
setColumn in class AllMatrices
Parameters:
k - number of the column in the matrix
d - the given column of the matrix

addColumn

public void addColumn(int k,
                      double factor,
                      double[] x)
Add a column of the matrix multiplied by a factor to x, x = x + A[][k] Legal range of the integer argument is 0 <= k < K.
The corresponding Matlab expression would be: x = x+f*A(:,k+1). Note that this function can not be used from Matlab, use getColumn(k) to get A(:,k+1) and calculate the new x in Matlab.

Overrides:
addColumn in class AllMatrices
Parameters:
k - number of the column the matrix A.
factor - a factor to multiply the column vector by.
x - an array of length N.

getRow

public void getRow(int n,
                   double[] r)
Copy a row of the matrix Legal range of the integer argument is 0 <= n < N. If argument is out of range a length K array of zeros should be returned.
The corresponding Matlab expression would be: r = A(n+1,:).

Overrides:
getRow in class AllMatrices
Parameters:
n - number of the row in the matrix A.
r - the given row of matrix A.

setRow

public void setRow(int n,
                   double[] r)
Set a row of the matrix Legal range of the integer argument is 0 <= n < N. If argument is out of range an IllegalArgumentException is thrown.
The corresponding Matlab expression would be: A(n+1,:) = r.

Overrides:
setRow in class AllMatrices
Parameters:
n - number of the row in the matrix A.
r - the given row of matrix A.

setAll

public void setAll(double[] vals)
Set all entries of to matrix to the supplied new values If argument is wrong length an IllegalArgumentException is thrown.

Overrides:
setAll in class AllMatrices
Parameters:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).

sumAll

public double sumAll()
Sum of all elements in matrix

Overrides:
sumAll in class AllMatrices
Returns:
sum of all elements

timeseqScaleColumns

public void timeseqScaleColumns(DiagonalMatrix D)
Scale the columns of this, A *= D which is A = A * D.

Parameters:
D - Diagonal matrix of size K-by-K, class DiagonalMatrix
Throws:
java.lang.IllegalArgumentException

timeseqScaleRows

public void timeseqScaleRows(DiagonalMatrix D)
Scale the rows of this, A *= D which is A = D * A.

Parameters:
D - Diagonal matrix of size N-by-N, class DiagonalMatrix
Throws:
java.lang.IllegalArgumentException