SSJ
V. 2.6.2.

umontreal.iro.lecuyer.util
Class DMatrix

java.lang.Object
  extended by umontreal.iro.lecuyer.util.DMatrix

public class DMatrix
extends Object

This class implements a few methods for matrix calculations with double numbers.


Constructor Summary
DMatrix(DMatrix that)
          Copy constructor.
DMatrix(double[][] data, int r, int c)
          Creates a new DMatrix with r rows and c columns using the data in data.
DMatrix(int r, int c)
          Creates a new DMatrix with r rows and c columns.
 
Method Summary
static void CholeskyDecompose(double[][] M, double[][] L)
          Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.
static DoubleMatrix2D CholeskyDecompose(DoubleMatrix2D M)
          Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.
static void copy(double[][] M, double[][] R)
          Copies the matrix M into R.
static double[][] exp(double[][] A)
          Similar to exp(A).
static DoubleMatrix2D exp(DoubleMatrix2D A)
          Returns eA, the exponential of the square matrix A.
static DoubleMatrix2D expBidiagonal(DoubleMatrix2D A)
          Returns eA, the exponential of the bidiagonal square matrix A.
static DoubleMatrix1D expBidiagonal(DoubleMatrix2D A, DoubleMatrix1D b)
          Computes c = eAb, where eA is the exponential of the bidiagonal square matrix A.
static DoubleMatrix2D expmiBidiagonal(DoubleMatrix2D A)
          Computes eA - I, where eA is the exponential of the bidiagonal square matrix A.
static DoubleMatrix1D expmiBidiagonal(DoubleMatrix2D A, DoubleMatrix1D b)
          Computes c = (eA - I)b, where eA is the exponential of the bidiagonal square matrix A.
 double get(int row, int column)
          Returns the matrix element in the specified row and column.
 int numColumns()
          Returns the number of columns of the DMatrix.
 int numRows()
          Returns the number of rows of the DMatrix.
static void PCADecompose(double[][] M, double[][] A, double[] lambda)
          Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M.
static DoubleMatrix2D PCADecompose(DoubleMatrix2D M, double[] lambda)
          Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M.
 void set(int row, int column, double value)
          Sets the value of the element in the specified row and column.
static double[] solveLU(double[][] A, double[] b)
          Solves the matrix equation Ax = b using LU decomposition.
static void solveTriangular(DoubleMatrix2D U, DoubleMatrix2D B, DoubleMatrix2D X)
          Solve the triangular matrix equation UX = B for X.
 String toString()
          Creates a String containing all the data of the DMatrix.
static String toString(double[][] M)
          Returns matrix M as a string.
 DMatrix transpose()
          Returns the transposed matrix.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DMatrix

public DMatrix(int r,
               int c)
Creates a new DMatrix with r rows and c columns.

Parameters:
r - the number of rows
c - the number of columns

DMatrix

public DMatrix(double[][] data,
               int r,
               int c)
Creates a new DMatrix with r rows and c columns using the data in data.

Parameters:
data - the data of the new DMatrix
r - the number of rows
c - the number of columns

DMatrix

public DMatrix(DMatrix that)
Copy constructor.

Parameters:
that - the DMatrix to copy
Method Detail

CholeskyDecompose

public static void CholeskyDecompose(double[][] M,
                                     double[][] L)
Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.

Parameters:
M - the input matrix
L - the Cholesky lower triangular matrix

CholeskyDecompose

public static DoubleMatrix2D CholeskyDecompose(DoubleMatrix2D M)
Given a symmetric positive-definite matrix M, performs the Cholesky decomposition of M and returns the result as a lower triangular matrix L, such that M = LLT.

Parameters:
M - the input matrix
Returns:
the Cholesky lower triangular matrix

PCADecompose

public static void PCADecompose(double[][] M,
                                double[][] A,
                                double[] lambda)
Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M. Puts the eigenvalues, which are the diagonal elements of matrix Λ, sorted by decreasing size, in vector lambda, and puts matrix A = U(Λ)1/2 in A.

Parameters:
M - input matrix
A - matrix square root of M
lambda - the eigenvalues

PCADecompose

public static DoubleMatrix2D PCADecompose(DoubleMatrix2D M,
                                          double[] lambda)
Computes the principal components decomposition M = UΛUt by using the singular value decomposition of matrix M. Puts the eigenvalues, which are the diagonal elements of matrix Λ, sorted by decreasing size, in vector lambda. Returns matrix A = U(Λ)1/2.

Parameters:
M - input matrix
lambda - the eigenvalues
Returns:
matrix square root of M

solveLU

public static double[] solveLU(double[][] A,
                               double[] b)
Solves the matrix equation Ax = b using LU decomposition. A is a square matrix, b and x are vectors. Returns the solution x.

Parameters:
A - square matrix
b - right side vector
Returns:
the solution vector

solveTriangular

public static void solveTriangular(DoubleMatrix2D U,
                                   DoubleMatrix2D B,
                                   DoubleMatrix2D X)
Solve the triangular matrix equation UX = B for X. U is a square upper triangular matrix. B and X must have the same number of columns.

Parameters:
U - input matrix
B - right-hand side matrix
X - output matrix

exp

public static double[][] exp(double[][] A)
Similar to exp(A).

Parameters:
A - input matrix
Returns:
the exponential of A

exp

public static DoubleMatrix2D exp(DoubleMatrix2D A)
Returns eA, the exponential of the square matrix A. The scaling and squaring method is used with Padé approximants to compute the exponential.

Parameters:
A - input matrix
Returns:
the exponential of A

expBidiagonal

public static DoubleMatrix2D expBidiagonal(DoubleMatrix2D A)
Returns eA, the exponential of the bidiagonal square matrix A. The only non-zero elements of A are on the diagonal and on the first superdiagonal. This method is faster than exp(A) because of the special form of A.

Parameters:
A - bidiagonal matrix
Returns:
eA

expBidiagonal

public static DoubleMatrix1D expBidiagonal(DoubleMatrix2D A,
                                           DoubleMatrix1D b)
Computes c = eAb, where eA is the exponential of the bidiagonal square matrix A. The only non-zero elements of A are on the diagonal and on the first superdiagonal. Uses the scaling and squaring method with Padé approximants. Returns c.

Parameters:
A - bidiagonal matrix
Returns:
eA

expmiBidiagonal

public static DoubleMatrix2D expmiBidiagonal(DoubleMatrix2D A)
Computes eA - I, where eA is the exponential of the bidiagonal square matrix A. The only non-zero elements of A are on the diagonal and on the first superdiagonal. Uses the scaling and squaring method with Padé approximants. Returns eA - I.

Parameters:
A - bidiagonal matrix
Returns:
(eA - I)b

expmiBidiagonal

public static DoubleMatrix1D expmiBidiagonal(DoubleMatrix2D A,
                                             DoubleMatrix1D b)
Computes c = (eA - I)b, where eA is the exponential of the bidiagonal square matrix A. The only non-zero elements of A are on the diagonal and on the first superdiagonal. Uses the scaling and squaring method with a Taylor expansion. Returns c.

Parameters:
A - bidiagonal matrix
b - vector
Returns:
c

copy

public static void copy(double[][] M,
                        double[][] R)
Copies the matrix M into R.

Parameters:
M - original matrix
R - output matrix

toString

public static String toString(double[][] M)
Returns matrix M as a string. It is displayed in matrix form, with each row on a line.

Returns:
the content of M

toString

public String toString()
Creates a String containing all the data of the DMatrix. The result is displayed in matrix form, with each row on a line.

Overrides:
toString in class Object
Returns:
the content of the DMatrix

numRows

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

Returns:
the number of rows

numColumns

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

Returns:
the number of columns

get

public double get(int row,
                  int column)
Returns the matrix element in the specified row and column.

Parameters:
row - the row of the selected element
column - the column of the selected element
Returns:
the value of the element
Throws:
IndexOutOfBoundsException - if the selected element would be outside the DMatrix

set

public void set(int row,
                int column,
                double value)
Sets the value of the element in the specified row and column.

Parameters:
row - the row of the selected element
column - the column of the selected element
value - the new value of the element
Throws:
IndexOutOfBoundsException - if the selected element would be outside the DMatrix

transpose

public DMatrix transpose()
Returns the transposed matrix. The rows and columns are interchanged.

Returns:
the transposed matrix

SSJ
V. 2.6.2.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.