SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.util.DMatrix Class Reference

This class implements a few methods for matrix calculations when the matrix entries are in double. More...

Public Member Functions

 DMatrix (int r, int c)
 Creates a new DMatrix with r rows and c columns.
 DMatrix (double[][] data, int r, int c)
 Creates a new DMatrix with r rows and c columns using the data in data.
 DMatrix (DMatrix that)
 Copy constructor.
String toString ()
 Creates a String containing all the data of the DMatrix.
int numRows ()
 Returns the number of rows of the DMatrix.
int numColumns ()
 Returns the number of columns of the DMatrix.
double get (int row, int column)
 Returns the matrix element in the specified row and column.
void set (int row, int column, double value)
 Sets the value of the element in the specified row and column.
DMatrix transpose ()
 Returns the transposed matrix.

Static Public Member Functions

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 = L L^T\).
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 = L L^T\).
static void PCADecompose (double[][] M, double[][] A, double[] lambda)
 Computes the principal components decomposition \(M\) =.
static DoubleMatrix2D PCADecompose (DoubleMatrix2D M, double[] lambda)
 Computes the principal components decomposition \(M\) =.
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\).
static double[][] exp (double[][] A)
 Similar to #exp(final DoubleMatrix2D).
static DoubleMatrix2D exp (final DoubleMatrix2D A)
 Returns \(e^A\), the exponential of the square matrix \(A\).
static DoubleMatrix2D expBidiagonal (final DoubleMatrix2D A)
 Returns \(e^A\), the exponential of the bidiagonal square matrix.
static DoubleMatrix1D expBidiagonal (final DoubleMatrix2D A, final DoubleMatrix1D b)
 Computes \(c = e^A b\), where \(e^A\) is the exponential of the bidiagonal square matrix \(A\).
static DoubleMatrix2D expmiBidiagonal (final DoubleMatrix2D A)
 Computes \(e^A - I\), where \(e^A\) is the exponential of the bidiagonal square matrix \(A\).
static DoubleMatrix1D expmiBidiagonal (final DoubleMatrix2D A, final DoubleMatrix1D b)
 Computes \(c = (e^A - I)b\), where \(e^A\) is the exponential of the bidiagonal square matrix \(A\).
static void copy (double[][] M, double[][] R)
 Copies the matrix \(M\) into \(R\).
static String toString (double[][] M)
 Returns matrix \(M\) as a string.

Static Package Functions

static void multBand (final DoubleMatrix2D A, int sa, final DoubleMatrix2D B, int sb, DoubleMatrix2D C)
 Matrix multiplication \(C = AB\).
static void multBand (DoubleMatrix2D A, int sa, double h)
 Multiplication of the matrix \(A\) by the scalar \(h\).
static void addMultBand (double g, DoubleMatrix2D A, int sa, double h, final DoubleMatrix2D B, int sb)
 Addition of the matrices \(gA + hB\) after multiplication with the scalars \(g\) and \(h\).

Detailed Description

This class implements a few methods for matrix calculations when the matrix entries are in double.

Definition at line 38 of file DMatrix.java.

Constructor & Destructor Documentation

◆ DMatrix() [1/3]

umontreal.ssj.util.DMatrix.DMatrix ( int r,
int c )

Creates a new DMatrix with r rows and c columns.

Parameters
rthe number of rows
cthe number of columns

Definition at line 268 of file DMatrix.java.

◆ DMatrix() [2/3]

umontreal.ssj.util.DMatrix.DMatrix ( double data[][],
int r,
int c )

Creates a new DMatrix with r rows and c columns using the data in data.

Parameters
datathe data of the new DMatrix
rthe number of rows
cthe number of columns

Definition at line 282 of file DMatrix.java.

◆ DMatrix() [3/3]

umontreal.ssj.util.DMatrix.DMatrix ( DMatrix that)

Copy constructor.

Parameters
thatthe DMatrix to copy

Definition at line 294 of file DMatrix.java.

Member Function Documentation

◆ addMultBand()

void umontreal.ssj.util.DMatrix.addMultBand ( double g,
DoubleMatrix2D A,
int sa,
double h,
final DoubleMatrix2D B,
int sb )
staticpackage

Addition of the matrices \(gA + hB\) after multiplication with the scalars \(g\) and \(h\).

\(A\) is a square banded upper triangular matrix. It has a non-zero diagonal, sa superdiagonals, and thus a bandwidth of sa + 1. Similarly for \(B\) which has a bandwidth of sb + 1. The result is put back in \(A\).

Parameters
gcoefficient multiplying A
Ainput and output matrix
sanumber of superdiagonals of A
hcoefficient multiplying B
Binput matrix
sbnumber of superdiagonals of B

Definition at line 812 of file DMatrix.java.

◆ CholeskyDecompose() [1/2]

void umontreal.ssj.util.DMatrix.CholeskyDecompose ( double M[][],
double L[][] )
static

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 = L L^T\).

Parameters
Mthe input matrix
Lthe Cholesky lower triangular matrix

Definition at line 306 of file DMatrix.java.

◆ CholeskyDecompose() [2/2]

DoubleMatrix2D umontreal.ssj.util.DMatrix.CholeskyDecompose ( DoubleMatrix2D M)
static

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 = L L^T\).

Parameters
Mthe input matrix
Returns
the Cholesky lower triangular matrix

Definition at line 328 of file DMatrix.java.

◆ copy()

void umontreal.ssj.util.DMatrix.copy ( double M[][],
double R[][] )
static

Copies the matrix \(M\) into \(R\).

Parameters
Moriginal matrix
Routput matrix

Definition at line 833 of file DMatrix.java.

◆ exp() [1/2]

double[][] umontreal.ssj.util.DMatrix.exp ( double A[][])
static

Similar to #exp(final DoubleMatrix2D).

Parameters
Ainput matrix
Returns
the exponential of \(A\)

Definition at line 436 of file DMatrix.java.

◆ exp() [2/2]

DoubleMatrix2D umontreal.ssj.util.DMatrix.exp ( final DoubleMatrix2D A)
static

Returns \(e^A\), the exponential of the square matrix \(A\).

The scaling and squaring method [82] is used with Padé approximants to compute the exponential.

Parameters
Ainput matrix
Returns
the exponential of \(A\)

Definition at line 450 of file DMatrix.java.

◆ expBidiagonal() [1/2]

DoubleMatrix2D umontreal.ssj.util.DMatrix.expBidiagonal ( final DoubleMatrix2D A)
static

Returns \(e^A\), 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(final DoubleMatrix2D) because of the special form of \(A\).

Parameters
Abidiagonal matrix
Returns
\(e^A\)

Definition at line 554 of file DMatrix.java.

◆ expBidiagonal() [2/2]

DoubleMatrix1D umontreal.ssj.util.DMatrix.expBidiagonal ( final DoubleMatrix2D A,
final DoubleMatrix1D b )
static

Computes \(c = e^A b\), where \(e^A\) 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 [82] with Padé approximants. Returns \(c\).

Parameters
Abidiagonal matrix
bvector
Returns
\(c\)

Definition at line 646 of file DMatrix.java.

◆ expmiBidiagonal() [1/2]

DoubleMatrix2D umontreal.ssj.util.DMatrix.expmiBidiagonal ( final DoubleMatrix2D A)
static

Computes \(e^A - I\), where \(e^A\) 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 [209], [82]  with Padé approximants. Returns \(e^A - I\).

Parameters
Abidiagonal matrix
Returns
\((e^A - I)b\)

Definition at line 663 of file DMatrix.java.

◆ expmiBidiagonal() [2/2]

DoubleMatrix1D umontreal.ssj.util.DMatrix.expmiBidiagonal ( final DoubleMatrix2D A,
final DoubleMatrix1D b )
static

Computes \(c = (e^A - I)b\), where \(e^A\) 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 [209], [82]  with a Taylor expansion. Returns \(c\).

Parameters
Abidiagonal matrix
bvector
Returns
\(c\)

Definition at line 708 of file DMatrix.java.

◆ get()

double umontreal.ssj.util.DMatrix.get ( int row,
int column )

Returns the matrix element in the specified row and column.

Parameters
rowthe row of the selected element
columnthe column of the selected element
Returns
the value of the element
Exceptions
IndexOutOfBoundsExceptionif the selected element would be outside the DMatrix

Definition at line 903 of file DMatrix.java.

◆ multBand() [1/2]

void umontreal.ssj.util.DMatrix.multBand ( DoubleMatrix2D A,
int sa,
double h )
staticpackage

Multiplication of the matrix \(A\) by the scalar \(h\).

\(A\) is a square banded upper triangular matrix. It has a non-zero diagonal, sa superdiagonals, and thus a bandwidth of sa + 1. The result of the multiplication is put back in \(A\).

Parameters
Ainput and output matrix
sanumber of superdiagonals of A
hscalar

Definition at line 786 of file DMatrix.java.

◆ multBand() [2/2]

void umontreal.ssj.util.DMatrix.multBand ( final DoubleMatrix2D A,
int sa,
final DoubleMatrix2D B,
int sb,
DoubleMatrix2D C )
staticpackage

Matrix multiplication \(C = AB\).

All three matrices are square, banded, and upper triangular. \(A\) has a non-zero diagonal, sa non-zero superdiagonals, and thus a bandwidth of sa + 1. The non-zero elements of

\(A_{ij}\) are those for which \(j - s_a \le i \le j\). Similarly for \(B\) which has a bandwidth of sb + 1. The resulting matrix \(C\) has sa + sb non-zero superdiagonals, and a bandwidth of sa + sb + 1.

Parameters
Ainput matrix
sanumber of superdiagonals of A
Binput matrix
sbnumber of superdiagonals of B
Cresult

Definition at line 772 of file DMatrix.java.

◆ numColumns()

int umontreal.ssj.util.DMatrix.numColumns ( )

Returns the number of columns of the DMatrix.

Returns
the number of columns

Definition at line 889 of file DMatrix.java.

◆ numRows()

int umontreal.ssj.util.DMatrix.numRows ( )

Returns the number of rows of the DMatrix.

Returns
the number of rows

Definition at line 880 of file DMatrix.java.

◆ PCADecompose() [1/2]

void umontreal.ssj.util.DMatrix.PCADecompose ( double M[][],
double A[][],
double[] lambda )
static

Computes the principal components decomposition \(M\) =.

\(U\Lambda U^{\mathsf{t}}\) by using the singular value decomposition of matrix \(M\). Puts the eigenvalues, which are the diagonal elements of matrix \(\Lambda\), sorted by decreasing size, in vector lambda, and puts matrix \(A = U\sqrt{\Lambda}\) in A.

Parameters
Minput matrix
Amatrix square root of M
lambdathe eigenvalues

Definition at line 345 of file DMatrix.java.

◆ PCADecompose() [2/2]

DoubleMatrix2D umontreal.ssj.util.DMatrix.PCADecompose ( DoubleMatrix2D M,
double[] lambda )
static

Computes the principal components decomposition \(M\) =.

\(U\Lambda U^{\mathsf{t}}\) by using the singular value decomposition of matrix \(M\). Puts the eigenvalues, which are the diagonal elements of matrix \(\Lambda\), sorted by decreasing size, in vector lambda. Returns matrix \(A = U\sqrt{\Lambda}\).

Parameters
Minput matrix
lambdathe eigenvalues
Returns
matrix square root of M

Definition at line 367 of file DMatrix.java.

◆ set()

void umontreal.ssj.util.DMatrix.set ( int row,
int column,
double value )

Sets the value of the element in the specified row and column.

Parameters
rowthe row of the selected element
columnthe column of the selected element
valuethe new value of the element
Exceptions
IndexOutOfBoundsExceptionif the selected element would be outside the DMatrix

Definition at line 919 of file DMatrix.java.

◆ solveLU()

double[] umontreal.ssj.util.DMatrix.solveLU ( double A[][],
double[] b )
static

Solves the matrix equation \(Ax = b\) using LU decomposition.

\(A\) is a square matrix, \(b\) and \(x\) are vectors. Returns the solution \(x\).

Parameters
Asquare matrix
bright side vector
Returns
the solution vector

Definition at line 396 of file DMatrix.java.

◆ solveTriangular()

void umontreal.ssj.util.DMatrix.solveTriangular ( DoubleMatrix2D U,
DoubleMatrix2D B,
DoubleMatrix2D X )
static

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
Uinput matrix
Bright-hand side matrix
Xoutput matrix

Definition at line 414 of file DMatrix.java.

◆ toString() [1/2]

String umontreal.ssj.util.DMatrix.toString ( )

Creates a String containing all the data of the DMatrix.

The result is displayed in matrix form, with each row on a line.

Returns
the content of the DMatrix

Definition at line 871 of file DMatrix.java.

◆ toString() [2/2]

String umontreal.ssj.util.DMatrix.toString ( double M[][])
static

Returns matrix \(M\) as a string.

It is displayed in matrix form, with each row on a line.

Returns
the content of \(M\)

Definition at line 847 of file DMatrix.java.

◆ transpose()

DMatrix umontreal.ssj.util.DMatrix.transpose ( )

Returns the transposed matrix.

The rows and columns are interchanged.

Returns
the transposed matrix

Definition at line 931 of file DMatrix.java.


The documentation for this class was generated from the following file: