SMatrix, square matrix class definition. More...
#include <SMatrix.h>
Public Member Functions | |
SMatrix (int dim_i=1) | |
Default initialisation, matrix dimension is dim_i, all elements are zero. | |
SMatrix (int dim_i, complex< double > diag) | |
Creates a diagonal matrix with dimension dim_i. | |
SMatrix (int dim_i, const complex< double > *Mtab_i) | |
Creates a matrix from array, read order from left to right. | |
SMatrix (int dim_i, double *real, double *imag) | |
Creates a matrix from real and imaginary arrays. | |
SMatrix (const SMatrix &m) | |
Constructor by copy. | |
~SMatrix () | |
Destructor. | |
int | getdim () const |
Send matrix dimension (dim). | |
void | redim (int ndim) |
Modify the matrix dimension. | |
void | setdiag (complex< double > diag) |
Creates a diagonal matrix, which all elements = diag. | |
void | setdiag (complex< double > *tab_diag) |
Transform the matrix in a diagonal matrix one, which all elements = array tab_diag. | |
void | print (const char *option="") const |
Output matrix as C code, ONLY for matlab mexPrintf(), cout<<SMatrix instead. | |
void | decompositionLU (SMatrix &L, SMatrix &U) |
LU decomposition. | |
void | decompositionCholesky (SMatrix &L, SMatrix &U) |
Cholesky decomposition. | |
void | SolveCrout (Ket b, Ket &x, SMatrix Lm, SMatrix Um) |
Solve linear system using Crout Method. | |
void | SolveSOR (Ket b, Ket &x) |
Solve linear system using SOR Method. | |
void | SolveGaussSeidel (Ket b, Ket &x) |
Solve linear system using Gauss Seidel Method. | |
complex< double > | getdetformal () const |
Calculate the determinant (formal mode). | |
complex< double > | getdet () const |
Calculate the determinant with LU decomposition. | |
complex< double > | gettrace () const |
Calculate the matrix trace. | |
double | getnorm () const |
Calculate the matrix norm. | |
double | getmax (double a[], int n) const |
Get the maximum value. | |
SMatrix | gettransposed () const |
Calculate the matrix transposed. | |
SMatrix | gethermitiantransposed () const |
Calculate the conjugate transposed. | |
SMatrix | getreducedmatrix (int row, int col) const |
Return a matrix without row i and column j. | |
SMatrix | getinversedformal () const |
Calculate the inversed matrix (formal mode). | |
SMatrix | getinversed () const |
Calculate the inversed matrix. | |
SMatrix | getabsmatrix () const |
Return matrix with the abs of all elements. | |
SMatrix | getexpm () const |
Calculate the matrix exponential using Pade algoritm (see Matlab for documentation). | |
complex< double > & | operator() (int i, int j) |
Acces to matrix elements. | |
complex< double > | operator() (int i, int j) const |
Read/Write matrix elements. | |
const SMatrix & | operator= (const SMatrix &m) |
Affectation operator. | |
SMatrix | operator+ (const SMatrix &m) const |
Addition operator. | |
SMatrix | operator- (const SMatrix &m) const |
Soustraction operator. | |
SMatrix | operator* (const SMatrix &m) const |
Multiplication operator. | |
SMatrix | operator/ (const SMatrix &m) const |
Division operator. | |
Friends | |
EXPORTED_FUNCTION SMatrix | operator* (complex< double > a, const SMatrix &m) |
Scalar complex - matrix multiplication. | |
EXPORTED_FUNCTION SMatrix | operator* (double a, const SMatrix &m) |
Scalar double - matrix multiplication. | |
EXPORTED_FUNCTION SMatrix | operator* (const SMatrix &m, complex< double > a) |
Matrix - scalar complex multiplication. | |
EXPORTED_FUNCTION SMatrix | operator* (const SMatrix &m, double a) |
Matrix - scalar double multiplication. | |
EXPORTED_FUNCTION SMatrix | operator* (complex< double > a, const SMatrix *m) |
Scalar complex - matrix pointer multiplication. | |
EXPORTED_FUNCTION SMatrix | operator/ (const SMatrix &m, double a) |
Matrix - scalar double division. | |
EXPORTED_FUNCTION SMatrix | operator/ (const SMatrix &m, complex< double > a) |
Matrix - scalar complex division. | |
EXPORTED_FUNCTION std::ostream & | operator<< (std::ostream &out, const SMatrix &m) |
Write to a flux, allow cout<<matrix; . |
SMatrix, square matrix class definition.
SMatrix is the square matrix base class for linear algebra operations. This class is composed by basical matrix operations, like trace, determinant, etc... You can also find numerical methods like LU decomposition, direct and interactives methods to solve linear systems. This class provides a user friend interface for load, create and get information from matrices, this is the mother class of Quantum Operators (QOperator).
SMatrix::SMatrix | ( | int | dim_i = 1 |
) |
Default initialisation, matrix dimension is dim_i, all elements are zero.
To create a matrix with all elements 0, you need to pass a valid dimension (dim_i > 0).
dim_i | Matrix row = column dimension. |
SMatrix::SMatrix | ( | int | dim_i, | |
complex< double > | diag | |||
) |
Creates a diagonal matrix with dimension dim_i.
To create a diagonal matrix, you pass the matrix dimension and the non zero element that will be put in the diagonal.
dim_i | Matrix row = column dimension. | |
diag | Complex number with double precision that will be put in the diagonal. |
SMatrix::SMatrix | ( | int | dim_i, | |
const complex< double > * | Mtab_i | |||
) |
Creates a matrix from array, read order from left to right.
To create a matrix from a complex<double> array that contains matrix data, you pass the matrix dimension and the data array.
dim_i | Matrix row = column dimension. | |
Mtab_i | Complex double precision array with all data. The data is put from left to right, in other words we fix the row and change columns. |
SMatrix::SMatrix | ( | int | dim_i, | |
double * | real, | |||
double * | imag | |||
) |
Creates a matrix from real and imaginary arrays.
SMatrix::SMatrix | ( | const SMatrix & | m | ) |
SMatrix::~SMatrix | ( | ) |
Destructor.
Destroy all matrix array elements.
Cholesky decomposition.
To elaborate a Cholesky decomposition, you need to pass the lower and upper matrices to be elaborated.
L | Lower matrix | |
U | Upper matrix |
SMatrix SMatrix::getabsmatrix | ( | ) | const |
Return matrix with the abs of all elements.
complex< double > SMatrix::getdet | ( | ) | const |
Calculate the determinant with LU decomposition.
complex< double > SMatrix::getdetformal | ( | ) | const |
Calculate the determinant (formal mode).
int SMatrix::getdim | ( | ) | const [inline] |
Send matrix dimension (dim).
SMatrix SMatrix::getexpm | ( | ) | const |
Calculate the matrix exponential using Pade algoritm (see Matlab for documentation).
SMatrix SMatrix::gethermitiantransposed | ( | ) | const |
Calculate the conjugate transposed.
SMatrix SMatrix::getinversed | ( | ) | const |
Calculate the inversed matrix.
SMatrix SMatrix::getinversedformal | ( | ) | const |
Calculate the inversed matrix (formal mode).
double SMatrix::getmax | ( | double | a[], | |
int | n | |||
) | const |
Get the maximum value.
a | Your array. | |
n | Array dimension. |
double SMatrix::getnorm | ( | ) | const |
Calculate the matrix norm.
SMatrix SMatrix::getreducedmatrix | ( | int | row, | |
int | col | |||
) | const |
Return a matrix without row i and column j.
row | Row to be removed. | |
col | Column to be removed. |
complex< double > SMatrix::gettrace | ( | ) | const |
Calculate the matrix trace.
SMatrix SMatrix::gettransposed | ( | ) | const |
Calculate the matrix transposed.
complex<double> SMatrix::operator() | ( | int | i, | |
int | j | |||
) | const [inline] |
Read/Write matrix elements.
complex<double>& SMatrix::operator() | ( | int | i, | |
int | j | |||
) | [inline] |
Acces to matrix elements.
Multiplication operator.
Allow you to multiply 2 or more operators, i.e: A = A*B*...*C;
Addition operator.
Allow you to sum 2 or more operators, i.e: A = A + B + ... + C;
Soustraction operator.
Allow you to subtracte 2 or more operators, i.e: A = A - B - ... - C;
Division operator.
Allow you to divide 2 or more operators, i.e: A = A/B/.../C;
void SMatrix::print | ( | const char * | option = "" |
) | const |
Output matrix as C code, ONLY for matlab mexPrintf(), cout<<SMatrix instead.
You can output matrix using this command i.e.: SMatrix A(...); A.print(); or A.print("expo");
option | If you pass the option "expo" all matrix elements will be showed with the exponential notation, else data will be showed as doubles. |
void SMatrix::redim | ( | int | ndim | ) |
Modify the matrix dimension.
To modify the dimension of a matrix, you pass the new dimension.
ndim | New matrix dimension. |
void SMatrix::setdiag | ( | complex< double > * | tab_diag | ) |
Transform the matrix in a diagonal matrix one, which all elements = array tab_diag.
To create a diagonal matrix, you need to pass a complex array that will be put in the diagonal.
tab_diag | Complex array that contains the elements to be put in the diagonal. |
void SMatrix::setdiag | ( | complex< double > | diag | ) |
Creates a diagonal matrix, which all elements = diag.
To create a diagonal matrix, you need to pass a complex number to be put in the diagonal.
diag | Complex number to be put in the diagonal. |
Solve linear system using Crout Method.
To solve a linear system A*x=b, you pass b and an empty x, you also need to pass the LU matrix from A.
b | The know vector. | |
x | The solution vector. | |
Lm | The lower triangular matrix. | |
Um | The upper triangular matrix. |
Solve linear system using Gauss Seidel Method.
To solve a linear system A*x=b, you pass b and an empty x.
b | The know vector. | |
x | The solution vector. |
Solve linear system using SOR Method.
To solve a linear system A*x=b, you pass b and an empty x.
b | The know vector. | |
x | The solution vector. |
Scalar complex - matrix pointer multiplication.
Matrix - scalar double multiplication.
Matrix - scalar complex multiplication.
Scalar double - matrix multiplication.
Scalar complex - matrix multiplication.
Matrix - scalar complex division.
Matrix - scalar double division.
EXPORTED_FUNCTION std::ostream& operator<< | ( | std::ostream & | out, | |
const SMatrix & | m | |||
) | [friend] |
Write to a flux, allow cout<<matrix; .