mpv2
Class BandMatrix

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

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

This class is a band diagonal matrix implementation of the AllMatrices superclass. The N-by-K matrix A is represented as an array of column vectors, and for each stored array (column vector) it is also stored how many zeros that preceed this array in the column vector of the matrix. Thus the lengths of the stored column vectors are usualle less than N.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class mpv2.AllMatrices
K, N
 
Constructor Summary
BandMatrix(double[][] A)
          Construct a matrix from a 2-D array.
BandMatrix(int iN, int iK)
          Construct a N×K matrix with only zero values.
BandMatrix(int iN, int iK, double[] vals)
          Construct a N×K matrix or dictionary with values from given one-dimensional array (which represents the matrix).
 
Method Summary
 void addColumn(int k, double factor, double[] x)
          Add a column of the matrix multiplied by a factor to a given vector.
 double get(int n, int k)
          Return an entry of the matrix.
 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.
 double innerProduct(int k1, int k2)
          Returns the inner product of two matrix column vectors.
 void set(int n, int k, double val)
          Set an entry (a value) in the matrix.
 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[] col)
          Replace a column in the dictionary with the given column vector.
 void times(double[] y, double[] x)
          Multiplies the matrix by an array.
 void transposeTimes(double[] x, double[] y)
          Multiplies the transposed matrix by an array.
 
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, getRow, getRowDimension, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, getValue, lu, lup, norm1, norm2, normF, normInf, pluseqOuterProduct, print, print, print, print, qr, rank, setRow, setValue, sumAll, svd, times, times, times, trace, transposeTimes, transposeTimes, transposeTimes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BandMatrix

public BandMatrix(int iN,
                  int iK)
Construct a N×K matrix with only zero values.

Parameters:
iN - number of rows, i.e. length of column vectors of the matrix.
iK - number of columns

BandMatrix

public BandMatrix(int iN,
                  int iK,
                  double[] vals)
Construct a N×K matrix or dictionary with values from given one-dimensional array (which represents the matrix). Length of the array should be N*K.

Parameters:
iN - number of rows, i.e. length of column vectors of the matrix.
iK - number of columns
vals - the values (ordered by column)

BandMatrix

public BandMatrix(double[][] A)
Construct a matrix from a 2-D array.

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

get

public double get(int n,
                  int k)
Return an entry of the matrix. Note that the row, i.e. position in the column, is given first, the second argument is the column number. We should have: 0 <= n < N and 0 <= k < K. If any argument is outside legal range 0.0 is returned without error or warning.

Specified by:
get in class AllMatrices
Parameters:
n - row number for the returned entry value.
k - column number for the returned entry value.
Returns:
A(i,j)

set

public void set(int n,
                int k,
                double val)
Set an entry (a value) in the matrix. Note that the row, i.e. position in the column, is given first, the second argument is the column number. We should have: 0 <= n < N and 0 <= k < K. If any argument is outside legal range nothing is done.

Specified by:
set in class AllMatrices
Parameters:
n - row number for the entry value to be changed.
k - column number for the entry value to be changed.
val - the value to be put into the given entry of the dictionary.

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[] col)
Replace a column in the dictionary with the given column vector. The column should be of length N. We should have: 0 <= k < K. If any argument is outside legal dimension or range nothing is done.

Overrides:
setColumn in class AllMatrices
Parameters:
k - column number for the column to be changed.
col - the value to be put into the given entry of the dictionary.

addColumn

public void addColumn(int k,
                      double factor,
                      double[] x)
Add a column of the matrix multiplied by a factor to a given vector. Legal range of the integer argument is 0 <= k < K.
The corresponding Matlab expression would be: x = x+factor*D(:,k+1).

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

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).

innerProduct

public double innerProduct(int k1,
                           int k2)
Returns the inner product of two matrix column vectors. Legal range is 0 <= k1 < K and 0 <= k2 < K.
If k1 or k2 is out of range, 0.0 is returned.

Overrides:
innerProduct in class AllMatrices
Parameters:
k1 - number for the first column.
k2 - number for the second column.

times

public void times(double[] y,
                  double[] x)
Multiplies the matrix by an array. The dimensions are: A is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: x = A*y.

Overrides:
times in class AllMatrices
Parameters:
y - the input array
x - the results as an array of length N.

transposeTimes

public void transposeTimes(double[] x,
                           double[] y)
Multiplies the transposed matrix by an array. The dimensions are: A is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: y = A'*x.

Overrides:
transposeTimes in class AllMatrices
Parameters:
x - the input array
y - the results as an array of length K.