Matrix of generic size. The elements are stored in a one-dimensional array in row-major order. More...
#include <fMatrix.h>
Public Member Functions | |
int | col () const |
Returns the number of columns. | |
double * | data () const |
Returns the pointer to the first element. | |
void | ddiv (const fMat &mat1, const fMat &mat2) |
Element-wise division: ./ operator in MATLAB. | |
double | det (void) |
Computes the determinant. | |
void | dmul (const fMat &mat1, const fMat &mat2) |
Element-wise multiplication: .* operator in MATLAB. | |
int | eig (fVec &wr, fVec &wi) |
Computes the eigenvalues. | |
int | eig (fVec &wr, fVec &wi, fMat &v) |
Computes the eigenvalues and eigenvectors. | |
int | eig (fVec &wr, fVec &wi, fMat &vr, fMat &vi) |
Computes the eigenvalues and eigenvectors. | |
fMat () | |
Default constructor. | |
fMat (int m, int n, double *ini=0) | |
Constructor with size and initial values (optional). | |
fMat (int m, int n, double ini) | |
Constructor with size and common initial values. | |
fMat (const fMat &ini) | |
Copy constructor. | |
fMat (const fVec &ini) | |
Constructor from a vector. | |
void | get_submat (int row_start, int col_start, const fMat &allM) |
Extract a sub-matrix and set to myself. | |
void | identity () |
Creates an identity matrix (only for square matrices). | |
int | info () |
Returns the value of m_info. | |
int | inv_porfs (const fMat &) |
inverse of positive-definite, symmetric matrix | |
int | inv_posv (const fMat &) |
inverse of positive-definite, symmetric matrix | |
int | lineq_porfs (const fMat &A, const fMat &b) |
solve linear equation Ax = b, where A is positive-definite, symmetric | |
int | lineq_posv (const fMat &A, const fMat &b) |
solve linear equation Ax = b, where A is positive-definite, symmetric | |
operator double * () | |
Converts to an array of double. | |
double & | operator() (int i, int j) |
Returns the (non-constant) reference to the (i,j) element. | |
double | operator() (int i, int j) const |
Returns the value of the (i,j) element. | |
fMat | operator= (const fMat &mat) |
Assignment from a reference matrix. | |
void | operator= (double d) |
Assigns the same value to all elements. | |
int | resize (int i, int j) |
Changes the matrix size. | |
int | row () const |
Returns the number of rows. | |
void | set (double *_d) |
Sets the values from an array. | |
void | set_submat (int row_start, int col_start, const fMat &subM) |
Sets a sub-matrix of myself. | |
void | setinfo (int _info) |
Sets m_info. | |
int | svd (fMat &U, fVec &Sigma, fMat &VT) |
singular value decomposition | |
void | symmetric (char t= 'U') |
Change to symmetric matrix. | |
void | tran (const fMat &mat) |
Sets the transpose of a matrix. | |
void | tran () |
Transposes a matrix (only for square matrices). | |
void | zero () |
Creates a zero matrix. | |
~fMat () | |
Destructor. | |
functions | |
Operators in function forms (faster). | |
void | set (const fMat &mat) |
void | neg (const fMat &mat) |
void | add (const fMat &mat1, const fMat &mat2) |
void | add (const fMat &mat) |
void | sub (const fMat &mat1, const fMat &mat2) |
void | mul (const fMat &mat1, const fMat &mat2) |
void | mul (double d, const fMat &mat) |
void | mul (const fMat &mat, double d) |
void | mul_tran (const fMat &mat1, int trans_first) |
void | div (const fMat &mat, double d) |
Protected Attributes | |
int | m_info |
int | n_col |
int | n_row |
double * | p_data |
double | temp |
Friends | |
fMat | eigs (const fMat &mat, double *w) |
Compute the eigenvalues. | |
fMat | eigs2 (const fMat &mat, double *w) |
Compute the eigenvalues. | |
int | inv_col_replaced (const fMat &P, const fMat &q, const fMat &m2d, fMat &X, fMat &y) |
Computes the inverse when some columns are replaced. | |
int | inv_enlarge (const fMat &m12, const fMat &m21, const fMat &m22, const fMat &P, fMat &X, fMat &y, fMat &z, fMat &w) |
Computes the inverse of an enlarged matrix. | |
int | inv_row_replaced (const fMat &P, const fMat &q, const fMat &m2d, fMat &X, fMat &y) |
Computes the inverse when some rows are replaced. | |
int | inv_shrink (const fMat &P, const fMat &q, const fMat &r, const fMat &s, fMat &X) |
Computes the inverse of a shrinked matrix. | |
ostream & | operator<< (ostream &ost, const fMat &mat) |
Outputs to a stream. | |
fMat | tran (const fMat &mat) |
Returns the transpose of a matrix. | |
friend | |
int | inv (const fMat &) |
inverse | |
int | p_inv (const fMat &) |
pseudo inverse | |
int | sr_inv (const fMat &mat, fVec &w_err, fVec &w_norm, double k) |
singularity-robust (SR) inverse | |
int | lineq (const fMat &A, const fMat &b) |
solve linear equation Ax = b | |
int | lineq_sr (const fMat &A, fVec &w_err, fVec &w_norm, double k, const fMat &b) |
solve linear equation Ax = b using SR-inverse | |
int | inv_svd (const fMat &, int lwork=-1) |
inverse | |
int | p_inv_svd (const fMat &, int lwork=-1) |
pseudo inverse | |
int | sr_inv_svd (const fMat &mat, fVec &w_err, fVec &w_norm, double k, int lwork=-1) |
SR-inverse. | |
int | lineq_svd (const fMat &A, const fMat &b, int lwork=-1) |
solve linear equation Ax = b | |
fMat | inv (const fMat &mat) |
inverse | |
fMat | p_inv (const fMat &mat) |
pseudo inverse | |
fMat | sr_inv (const fMat &mat, fVec &w_err, fVec &w_norm, double k) |
singularity-robust (SR) inverse | |
fMat | lineq (const fMat &A, const fMat &b) |
solve linear equation Ax = b | |
fMat | lineq_sr (const fMat &A, fVec &w_err, fVec &w_norm, double k, const fMat &b) |
solve linear equation Ax = b using SR-inverse | |
fMat | inv_svd (const fMat &mat, int lwork) |
inverse | |
fMat | p_inv_svd (const fMat &mat, int lwork) |
pseudo inverse | |
fMat | sr_inv_svd (const fMat &mat, fVec &w_err, fVec &w_norm, double k, int lwork) |
SR-inverse. | |
fMat | lineq_svd (const fMat &A, const fMat &b, int lwork) |
solve linear equation Ax = b | |
operators | |
void | operator+= (const fMat &mat) |
void | operator-= (const fMat &mat) |
void | operator*= (double d) |
void | operator/= (double d) |
fMat | operator- (const fMat &mat) |
fMat | operator+ (const fMat &mat1, const fMat &mat2) |
fMat | operator- (const fMat &mat1, const fMat &mat2) |
fMat | operator* (const fMat &mat1, const fMat &mat2) |
fVec | operator* (const fMat &mat, const fVec &vec) |
fMat | operator* (double d, const fMat &mat) |
fMat | operator* (const fMat &mat, double d) |
fMat | operator/ (const fMat &mat, double d) |
Matrix of generic size. The elements are stored in a one-dimensional array in row-major order.
fMat::fMat | ( | ) | [inline] |
fMat::fMat | ( | int | m, |
int | n, | ||
double * | ini = 0 |
||
) | [inline] |
fMat::fMat | ( | int | m, |
int | n, | ||
double | ini | ||
) | [inline] |
fMat::fMat | ( | const fMat & | ini | ) | [inline] |
fMat::fMat | ( | const fVec & | ini | ) |
Constructor from a vector.
Creates an nx1 matrix from a vector.
[in] | ini | The reference vector. |
Definition at line 21 of file fMatrix.cpp.
fMat::~fMat | ( | ) | [inline] |
Definition at line 1169 of file fMatrix.cpp.
double* fMat::data | ( | ) | const [inline] |
Element-wise division: ./ operator in MATLAB.
Definition at line 1737 of file fMatrix.cpp.
Computes the determinant.
Definition at line 1785 of file fMatrix.cpp.
Element-wise multiplication: .* operator in MATLAB.
Definition at line 1688 of file fMatrix.cpp.
Computes the eigenvalues.
Computes the eigenvalues.
[out] | wr | Vector of the real parts. |
[out] | wi | Vector of the imaginary parts. |
Definition at line 1800 of file fMatrix.cpp.
Computes the eigenvalues and eigenvectors.
Computes the eigenvalues and eigenvectors.
[out] | wr | Vector of the real parts of the eigenvalues. |
[out] | wi | Vector of the imaginary parts of the eigenvlaues. |
[out] | v | Eigenvectors. |
Definition at line 1819 of file fMatrix.cpp.
Computes the eigenvalues and eigenvectors.
Computes the eigenvalues and eigenvectors.
[out] | wr | Vector of the real parts of the eigenvalues. |
[out] | wi | Vector of the imaginary parts of the eigenvlaues. |
[out] | vr | Real parts of the eigenvectors. |
[out] | vi | Imaginary parts of the eigenvectors. |
Definition at line 1840 of file fMatrix.cpp.
Extract a sub-matrix and set to myself.
Extracts an n_row x n_col sub-matrix from a large matrix.
[in] | row_start | First row to extract. |
[in] | col_start | First column to extract. |
[in] | allM | The original matrix. |
Definition at line 32 of file fMatrix.cpp.
void fMat::identity | ( | ) |
Creates an identity matrix (only for square matrices).
Definition at line 1058 of file fMatrix.cpp.
int fMat::info | ( | ) | [inline] |
int fMat::inv_porfs | ( | const fMat & | A | ) |
inverse of positive-definite, symmetric matrix
Definition at line 780 of file fMatrix.cpp.
int fMat::inv_posv | ( | const fMat & | A | ) |
inverse of positive-definite, symmetric matrix
Definition at line 757 of file fMatrix.cpp.
int fMat::inv_svd | ( | const fMat & | , |
int | lwork = -1 |
||
) |
inverse
solve linear equation Ax = b, where A is positive-definite, symmetric
Definition at line 772 of file fMatrix.cpp.
solve linear equation Ax = b, where A is positive-definite, symmetric
Definition at line 746 of file fMatrix.cpp.
solve linear equation Ax = b using SR-inverse
Definition at line 1217 of file fMatrix.cpp.
void fMat::mul_tran | ( | const fMat & | mat1, |
int | trans_first | ||
) |
Definition at line 1241 of file fMatrix.cpp.
fMat::operator double * | ( | ) | [inline] |
void fMat::operator*= | ( | double | d | ) |
Reimplemented in fVec.
Definition at line 1110 of file fMatrix.cpp.
Definition at line 1096 of file fMatrix.cpp.
Definition at line 1103 of file fMatrix.cpp.
void fMat::operator/= | ( | double | d | ) |
Reimplemented in fVec.
Definition at line 1146 of file fMatrix.cpp.
Assignment from a reference matrix.
Definition at line 1152 of file fMatrix.cpp.
void fMat::operator= | ( | double | d | ) |
Assigns the same value to all elements.
Reimplemented in fVec.
Definition at line 1163 of file fMatrix.cpp.
int fMat::p_inv | ( | const fMat & | ) |
pseudo inverse
int fMat::p_inv_svd | ( | const fMat & | , |
int | lwork = -1 |
||
) |
pseudo inverse
int fMat::resize | ( | int | i, |
int | j | ||
) | [inline] |
Changes the matrix size.
Changes the size of the matrix. If the new size is the same as the previous, nothing happens (memory is not re-allocated). The values are not initialized.
[in] | i | The new row size. |
[in] | j | The new column size. |
Sets a sub-matrix of myself.
Sets subM as an subM.n_row x subM.n_col sub-matrix of myself.
[in] | row_start | First row to set. |
[in] | col_start | First column to set. |
[in] | subM | The original matrix. |
Definition at line 48 of file fMatrix.cpp.
void fMat::setinfo | ( | int | _info | ) | [inline] |
singularity-robust (SR) inverse
SR-inverse.
Definition at line 1196 of file fMatrix.cpp.
singular value decomposition
Performs singular-value decomposition (SVD) M = U*S*V^T.
[out] | U | An mxm matrix. |
[out] | Sigma | Vector of min(m, n) elements containing the diagonal elements of S |
[out] | VT | An nxn matrix, transpose of V. |
Definition at line 733 of file fMatrix.cpp.
void fMat::symmetric | ( | char | t = 'U' | ) |
Change to symmetric matrix.
Creates a symmetric matrix
[in] | t | Command- 'A': average, 'U': use upper triangle, 'L': use lower triangle |
Definition at line 88 of file fMatrix.cpp.
void fMat::tran | ( | const fMat & | mat | ) |
Sets the transpose of a matrix.
void fMat::tran | ( | ) |
Transposes a matrix (only for square matrices).
Definition at line 1040 of file fMatrix.cpp.
void fMat::zero | ( | ) | [inline] |
Compute the eigenvalues.
Definition at line 1659 of file fMatrix.cpp.
int inv_col_replaced | ( | const fMat & | P, |
const fMat & | q, | ||
const fMat & | m2d, | ||
fMat & | X, | ||
fMat & | y | ||
) | [friend] |
Computes the inverse when some columns are replaced.
Computes the inverse when some columns are replaced:
| X | = | M1 m2' |-1 | y |
where
| P | = | M1 m2 |-1 | q | | |
are known
Definition at line 1357 of file fMatrix.cpp.
int inv_enlarge | ( | const fMat & | m12, |
const fMat & | m21, | ||
const fMat & | m22, | ||
const fMat & | P, | ||
fMat & | X, | ||
fMat & | y, | ||
fMat & | z, | ||
fMat & | w | ||
) | [friend] |
Computes the inverse of an enlarged matrix.
Computes the inverse of an enlarged matrix:
| X y | = | M11 m12 |-1 | z w | | m21 m22 |
where M11, m12, m21, m22, and P=M11^{-1} are known
Definition at line 1288 of file fMatrix.cpp.
int inv_row_replaced | ( | const fMat & | P, |
const fMat & | q, | ||
const fMat & | m2d, | ||
fMat & | X, | ||
fMat & | y | ||
) | [friend] |
Computes the inverse when some rows are replaced.
Computes the inverse when some rows are replaced:
| X y | = | M1 |-1 | | | m2' |
where
| P q | = | M1 |-1 | | | m2 |
are known
Definition at line 1334 of file fMatrix.cpp.
int inv_shrink | ( | const fMat & | P, |
const fMat & | q, | ||
const fMat & | r, | ||
const fMat & | s, | ||
fMat & | X | ||
) | [friend] |
Computes the inverse of a shrinked matrix.
Computes the inverse of a shrinked matrix: X = M11^(-1) where
| P q | = | M11 m12 |-1 | r s | | m21 m22 |
are known
Definition at line 1318 of file fMatrix.cpp.
int fMat::inv_svd | ( | const fMat & | mat, |
int | lwork = -1 |
||
) | [friend] |
inverse
Definition at line 484 of file fMatrix.cpp.
solve linear equation Ax = b
Definition at line 137 of file fMatrix.cpp.
int fMat::lineq_sr | ( | const fMat & | A, |
fVec & | w_err, | ||
fVec & | w_norm, | ||
double | k, | ||
const fMat & | b | ||
) | [friend] |
solve linear equation Ax = b using SR-inverse
Definition at line 930 of file fMatrix.cpp.
solve linear equation Ax = b
Definition at line 416 of file fMatrix.cpp.
Definition at line 1268 of file fMatrix.cpp.
Definition at line 1412 of file fMatrix.cpp.
Definition at line 1130 of file fMatrix.cpp.
Definition at line 1138 of file fMatrix.cpp.
Definition at line 1187 of file fMatrix.cpp.
Definition at line 1088 of file fMatrix.cpp.
Definition at line 1208 of file fMatrix.cpp.
Definition at line 1435 of file fMatrix.cpp.
int fMat::p_inv | ( | const fMat & | mat | ) | [friend] |
pseudo inverse
Definition at line 191 of file fMatrix.cpp.
int fMat::p_inv_svd | ( | const fMat & | mat, |
int | lwork = -1 |
||
) | [friend] |
pseudo inverse
Definition at line 501 of file fMatrix.cpp.
singularity-robust (SR) inverse
Definition at line 226 of file fMatrix.cpp.
int fMat::sr_inv_svd | ( | const fMat & | mat, |
fVec & | w_err, | ||
fVec & | w_norm, | ||
double | k, | ||
int | lwork = -1 |
||
) | [friend] |
SR-inverse.
Definition at line 536 of file fMatrix.cpp.
void fMat::tran | ( | const fMat & | mat | ) | [friend] |
Returns the transpose of a matrix.
Definition at line 1013 of file fMatrix.cpp.
int fMat::m_info [protected] |
int fMat::n_col [protected] |
int fMat::n_row [protected] |
double* fMat::p_data [protected] |
double fMat::temp [protected] |