SSJ  3.3.1
Stochastic Simulation in Java
Public Member Functions | Static Public Member Functions | Static Package Functions | Package Attributes | List of all members
DMatrix Class Reference

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

Public Member Functions

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

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\). More...
 
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\). More...
 
static void PCADecompose (double[][] M, double[][] A, double[] lambda)
 Computes the principal components decomposition \(M\) = \(U\Lambda U^{\mathsf{t}}\) by using the singular value decomposition of matrix \(M\). More...
 
static DoubleMatrix2D PCADecompose (DoubleMatrix2D M, double[] lambda)
 Computes the principal components decomposition \(M\) = \(U\Lambda U^{\mathsf{t}}\) by using the singular value decomposition of matrix \(M\). More...
 
static double [] solveLU (double[][] A, double[] b)
 Solves the matrix equation \(Ax = b\) using LU decomposition. More...
 
static void solveTriangular (DoubleMatrix2D U, DoubleMatrix2D B, DoubleMatrix2D X)
 Solve the triangular matrix equation \(UX = B\) for \(X\). More...
 
static double [][] exp (double[][] A)
 Similar to #exp(final DoubleMatrix2D). More...
 
static DoubleMatrix2D exp (final DoubleMatrix2D A)
 Returns \(e^A\), the exponential of the square matrix \(A\). More...
 
static DoubleMatrix2D expBidiagonal (final DoubleMatrix2D A)
 Returns \(e^A\), the exponential of the bidiagonal square matrix \(A\). More...
 
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\). More...
 
static DoubleMatrix2D expmiBidiagonal (final DoubleMatrix2D A)
 Computes \(e^A - I\), where \(e^A\) is the exponential of the bidiagonal square matrix \(A\). More...
 
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\). More...
 
static void copy (double[][] M, double[][] R)
 Copies the matrix \(M\) into \(R\). More...
 
static String toString (double[][] M)
 Returns matrix \(M\) as a string. More...
 

Static Package Functions

static void addMultTriang (final DoubleMatrix2D A, DoubleMatrix1D b, double h)
 
static void multBand (final DoubleMatrix2D A, int sa, final DoubleMatrix2D B, int sb, DoubleMatrix2D C)
 Matrix multiplication \(C = AB\). More...
 
static void multBand (DoubleMatrix2D A, int sa, double h)
 Multiplication of the matrix \(A\) by the scalar \(h\). More...
 
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\). More...
 

Package Attributes

int c
 

Detailed Description

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

Constructor & Destructor Documentation

◆ DMatrix() [1/3]

DMatrix ( int  r,
int  c 
)

Creates a new DMatrix with r rows and c columns.

Parameters
rthe number of rows
cthe number of columns

◆ DMatrix() [2/3]

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

◆ DMatrix() [3/3]

DMatrix ( DMatrix  that)

Copy constructor.

Parameters
thatthe DMatrix to copy

Member Function Documentation

◆ addMultBand()

static void 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

◆ CholeskyDecompose() [1/2]

static void 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

◆ CholeskyDecompose() [2/2]

static DoubleMatrix2D 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

◆ copy()

static void copy ( double  M[][],
double  R[][] 
)
static

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

Parameters
Moriginal matrix
Routput matrix

◆ exp() [1/2]

static double [][] exp ( double  A[][])
static

Similar to #exp(final DoubleMatrix2D).

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

◆ exp() [2/2]

static DoubleMatrix2D exp ( final DoubleMatrix2D  A)
static

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

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

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

◆ expBidiagonal() [1/2]

static DoubleMatrix2D 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\)

◆ expBidiagonal() [2/2]

static DoubleMatrix1D 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 [85] with Padé approximants. Returns \(c\).

Parameters
Abidiagonal matrix
bvector
Returns
\(c\)

◆ expmiBidiagonal() [1/2]

static DoubleMatrix2D 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 [217], [85]  with Padé approximants. Returns \(e^A - I\).

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

◆ expmiBidiagonal() [2/2]

static DoubleMatrix1D 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 [217], [85]  with a Taylor expansion. Returns \(c\).

Parameters
Abidiagonal matrix
bvector
Returns
\(c\)

◆ get()

double 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

◆ multBand() [1/2]

static void 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

◆ multBand() [2/2]

static void 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

◆ numColumns()

int numColumns ( )

Returns the number of columns of the DMatrix.

Returns
the number of columns

◆ numRows()

int numRows ( )

Returns the number of rows of the DMatrix.

Returns
the number of rows

◆ PCADecompose() [1/2]

static void 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

◆ PCADecompose() [2/2]

static DoubleMatrix2D 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

◆ set()

void 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

◆ solveLU()

static double [] 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

◆ solveTriangular()

static void 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

◆ toString() [1/2]

static String 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\)

◆ toString() [2/2]

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.

Returns
the content of the DMatrix

◆ transpose()

DMatrix transpose ( )

Returns the transposed matrix.

The rows and columns are interchanged.

Returns
the transposed matrix

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