PARP Research Group Universidad de Murcia


Matrix Algebra
[Math functionality]

Matrix algebra related functions (see also source programs in directory examples/matrixalgebra-tests for an exhaustive set of examples of use). More...

Enumerations

enum  TQVSVD_Method {
  GSL_THIN_DECOMP_MOD, GSL_THIN_DECOMP, GSL_THIN_DECOMP_JACOBI, LAPACK_FULL_DGESVD,
  LAPACK_FULL_DGESDD, LAPACK_THIN_DGESVD, LAPACK_THIN_DGESDD
}
 

Available methods for Singular Value Decomposition (SVD).

More...
enum  TQVSV_Method {
  GSL_ONLY_DECOMP_MOD, GSL_ONLY_DECOMP, GSL_ONLY_DECOMP_JACOBI, LAPACK_ONLY_DGESVD,
  LAPACK_ONLY_DGESDD
}
 

Available methods for Singular Values only computation (SV).

More...
enum  TQVCholesky_Method { GSL_CHOLESKY, LAPACK_CHOLESKY_DPOTRF }
 

Available methods for Cholesky Decomposition.

More...
enum  TQVQR_Method { GSL_HOUSEHOLDER_THIN_QR, GSL_HOUSEHOLDER_FULL_QR, LAPACK_THIN_DGEQR2, LAPACK_FULL_DGEQR2 }
 

Available methods for QR Decomposition.

More...
enum  TQVLU_Method { GSL_LU, LAPACK_DGETRF }
 

Available methods for LU Decomposition.

More...
enum  TQVEigenDecomposition_Method { GSL_EIGENSYMM, LAPACK_DSYEV }
 

Available methods for EigenDecomposition.

More...
enum  TQVEigenValues_Method { GSL_EIGENSYMM_ONLY, LAPACK_DSYEV_ONLY }
 

Available methods for EigenValues only computation.

More...
enum  TQVSparseSolve_Method {
  QVMKL_DSS = 0, QVMKL_ISS = 1, QVCHOLMOD_DSS = 2, QV_SCG = 3,
  QV_BJPCG = 4, QV_DENSE = 5
}
 

Available methods for sparse linear system solving.

More...

Functions

void singularValueDecomposition (const QVMatrix &M, QVMatrix &U, QVVector &s, QVMatrix &V, const TQVSVD_Method method=DEFAULT_TQVSVD_METHOD)
 Obtains the Singular Value Decomposition (SVD) of a rectangular $ m \times n $ matrix M.
void solveFromSingularValueDecomposition (const QVMatrix &U, const QVVector &s, const QVMatrix &V, QVMatrix &X, const QVMatrix &B)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained singular value decomposition $M = U diag(s) V^T$.
void solveFromSingularValueDecomposition (const QVMatrix &U, const QVVector &s, const QVMatrix &V, QVVector &x, const QVVector &b)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained singular value decomposition $M = U diag(s) V^T$.
void solveBySingularValueDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, const TQVSVD_Method method=DEFAULT_TQVSVD_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the singular value decomposition $M = U diag(s) V^T$.
void solveBySingularValueDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, const TQVSVD_Method method=DEFAULT_TQVSVD_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the singular value decomposition $M = U diag(s) V^T$.
void solveBySingularValueDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, QVMatrix &U, QVVector &s, QVMatrix &V, const TQVSVD_Method method=DEFAULT_TQVSVD_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the singular value decomposition $M = U diag(s) V^T$.
void solveBySingularValueDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, QVMatrix &U, QVVector &s, QVMatrix &V, const TQVSVD_Method method=DEFAULT_TQVSVD_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the singular value decomposition $M = U diag(s) V^T$.
double singularValueDecompositionResidual (const QVMatrix &M, const QVMatrix &U, const QVVector &s, const QVMatrix &V)
 Checks for correctness of the SVD of a matrix.
void singularValues (const QVMatrix &M, QVVector &s, const TQVSV_Method method=DEFAULT_TQVSV_METHOD)
 Gets the singular values of a matrix.
double singularValuesResidual (const QVMatrix &M, const QVVector &s)
 Checks for correctness of the singular values of a matrix.
void CholeskyDecomposition (const QVMatrix &M, QVMatrix &L, const TQVCholesky_Method method=DEFAULT_TQVCHOLESKY_METHOD)
 Obtains the Cholesky decomposition of a symmetric and positive definite matrix.
void solveFromCholeskyDecomposition (const QVMatrix &L, QVMatrix &X, const QVMatrix &B)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained Cholesky decomposition $ M = L L^{T} $.
void solveFromCholeskyDecomposition (const QVMatrix &L, QVVector &x, const QVVector &b)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained Cholesky decomposition $ M = L L^{T} $.
void solveByCholeskyDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, const TQVCholesky_Method method=DEFAULT_TQVCHOLESKY_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the Cholesky decomposition $ M = L L^{T} $.
void solveByCholeskyDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, const TQVCholesky_Method method=DEFAULT_TQVCHOLESKY_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the Cholesky decomposition $ M = L L^{T} $.
void solveByCholeskyDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, QVMatrix &L, const TQVCholesky_Method method=DEFAULT_TQVCHOLESKY_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the Cholesky decomposition $ M = L L^{T} $.
void solveByCholeskyDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, QVMatrix &L, const TQVCholesky_Method method=DEFAULT_TQVCHOLESKY_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the Cholesky decomposition $ M = L L^{T} $.
double CholeskyDecompositionResidual (const QVMatrix &M, const QVMatrix &L)
 Checks for correctness of the Cholesky decomposition of a matrix.
void LUDecomposition (const QVMatrix &M, QVMatrix &P, QVMatrix &L, QVMatrix &U, const TQVLU_Method method=DEFAULT_TQVLU_METHOD)
 Obtains the LU decomposition of a rectangular $ m \times n $ matrix.
void solveFromLUDecomposition (const QVMatrix &P, const QVMatrix &L, const QVMatrix &U, QVMatrix &X, const QVMatrix &B)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained LU decomposition of M:
void solveFromLUDecomposition (const QVMatrix &P, const QVMatrix &L, const QVMatrix &U, QVVector &x, const QVVector &b)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained LU decomposition $ M = P L U $.
void solveByLUDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, const TQVLU_Method method=DEFAULT_TQVLU_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the LU decomposition $ M = P L U $.
void solveByLUDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, const TQVLU_Method method=DEFAULT_TQVLU_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the LU decomposition $ M = P L U $.
void solveByLUDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, QVMatrix &P, QVMatrix &L, QVMatrix &U, const TQVLU_Method method=DEFAULT_TQVLU_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the LU decomposition $ M = P L U $.
void solveByLUDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, QVMatrix &P, QVMatrix &L, QVMatrix &U, const TQVLU_Method method=DEFAULT_TQVLU_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the LU decomposition $ M = P L U $.
double LUDecompositionResidual (const QVMatrix &M, const QVMatrix &P, const QVMatrix &L, const QVMatrix &U)
 Checks for correctness of the LU decomposition of a matrix.
void QRDecomposition (const QVMatrix &M, QVMatrix &Q, QVMatrix &R, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Obtains the QR decomposition of a rectangular $ m \times n $ matrix.
double QRDecompositionResidual (const QVMatrix &M, const QVMatrix &Q, const QVMatrix &R)
 Checks for correctness of the QR decomposition of a matrix.
void QLDecomposition (const QVMatrix &M, QVMatrix &Q, QVMatrix &L, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Obtains the QL decomposition of a rectangular $ m \times n $ matrix.
double QLDecompositionResidual (const QVMatrix &M, const QVMatrix &Q, const QVMatrix &L)
 Checks for correctness of the QL decomposition of a matrix.
void RQDecomposition (const QVMatrix &M, QVMatrix &R, QVMatrix &Q, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Obtains the RQ decomposition of a rectangular $ m \times n $ matrix.
double RQDecompositionResidual (const QVMatrix &M, const QVMatrix &R, const QVMatrix &Q)
 Checks for correctness of the RQ decomposition of a matrix.
void LQDecomposition (const QVMatrix &M, QVMatrix &L, QVMatrix &Q, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Obtains the LQ decomposition of a rectangular $ m \times n $ matrix.
double LQDecompositionResidual (const QVMatrix &M, const QVMatrix &L, const QVMatrix &Q)
 Checks for correctness of the LQ decomposition of a matrix.
void solveFromQRDecomposition (const QVMatrix &Q, const QVMatrix &R, QVMatrix &X, const QVMatrix &B)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained QR decomposition of M:
void solveFromQRDecomposition (const QVMatrix &Q, const QVMatrix &R, QVVector &x, const QVVector &b)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained QR decomposition of M:
void solveByQRDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the QR decomposition of M:
void solveByQRDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the QR decomposition of M:
void solveByQRDecomposition (const QVMatrix &M, QVMatrix &X, const QVMatrix &B, QVMatrix &Q, QVMatrix &R, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Solves the linear system $M X = B$ for the unknown matrix $X$, using the QR decomposition of M:
void solveByQRDecomposition (const QVMatrix &M, QVVector &x, const QVVector &b, QVMatrix &Q, QVMatrix &R, const TQVQR_Method method=DEFAULT_TQVQR_METHOD)
 Solves the linear system $M x = b$ for the unknown vector $x$, using the QR decomposition of M:
void eigenDecomposition (const QVMatrix &M, QVVector &lambda, QVMatrix &Q, const TQVEigenDecomposition_Method method=DEFAULT_TQVEIGENDECOMPOSITION_METHOD)
 Obtains the eigen-decomposition of a symmetric matrix.
double eigenDecompositionResidual (const QVMatrix &M, const QVVector &lambda, const QVMatrix &Q)
 Checks for correctness of the eigendecomposition of a matrix.
void eigenValues (const QVMatrix &M, QVVector &lambda, const TQVEigenValues_Method method=DEFAULT_TQVEIGENVALUES_METHOD)
 Gets the eigenvalues of a matrix.
double eigenValuesResidual (const QVMatrix &M, const QVVector &lambda)
 Checks for correctness of the eigenvalues of a symmetric matrix.
QVMatrix pseudoInverse (const QVMatrix &M, const TQVSVD_Method method=DEFAULT_TQVSVD_METHOD, const double epsilon=1.0E-10)
 Obtains the Moore–Penrose pseudoinverse of a matrix.
double determinant (const QVMatrix &M, const TQVLU_Method method=DEFAULT_TQVLU_METHOD)
 Obtains the determinant of a square matrix.
void solveHomogeneous (const QVMatrix &A, QVector< double > &x, const TQVSVD_Method method=DEFAULT_TQVSVD_METHOD)
 Solves an homogeneous linear system of equations.
double solveResidual (const QVMatrix &M, const QVMatrix &X, const QVMatrix &B)
 Returns the residual of the solution to a linear matrix equation.
double solveResidual (const QVMatrix &M, const QVVector &x, const QVVector &b)
 Returns the residual of the solution to a linear vector equation.
double sparseSolve (const QVSparseBlockMatrix &M, QVVector &x, const QVVector &b, const bool isSymmetric=false, const bool isPosDefinite=false, const TQVSparseSolve_Method method=DEFAULT_TQVSPARSESOLVE_METHOD, const bool start_from_x=false, const bool iters_or_resid=true, const int iters=0, const double resid=1.0E-10, int &final_iter_count=dummy)
 Solves a sparse system of linear equations, taking advantage of sparseness to accelerate the computation.
bool solveHomogeneous (const QVSparseBlockMatrix &A, QVVector &x, const int maxIterations=10, const double minRelativeError=0.0, const TQVSparseSolve_Method method=QVMKL_DSS)
 Solves a sparse homogeneous linear system using the inverse iteration algorithm and the MKL sparse routines.

Detailed Description

Matrix algebra related functions (see also source programs in directory examples/matrixalgebra-tests for an exhaustive set of examples of use).


Enumeration Type Documentation

Available methods for Singular Value Decomposition (SVD).

Enumerator:
GSL_THIN_DECOMP_MOD 

GSL Golub-Reinsch modified algorithm (thin); faster for M >> N.

GSL_THIN_DECOMP 

GSL Golub-Reinsch default algorithm (thin)

GSL_THIN_DECOMP_JACOBI 

GSL one sided Jacobi algorithm (thin); slower, but more accurate.

LAPACK_FULL_DGESVD 

Lapack DGESVD method (full);

LAPACK_FULL_DGESDD 

Lapack DGESDD divide and conquer method (full);

LAPACK_THIN_DGESVD 

Lapack DGESVD method (thin);

LAPACK_THIN_DGESDD 

Lapack DGESDD divide and conquer method (thin);

Definition at line 75 of file qvmatrixalgebra.h.

Available methods for Singular Values only computation (SV).

Enumerator:
GSL_ONLY_DECOMP_MOD 

Only returns singular values, but computes complete decomposition using GSL_THIN_DECOMP_MOD.

GSL_ONLY_DECOMP 

Only returns singular values, but computes complete decomposition using GSL_THIN_DECOMP.

GSL_ONLY_DECOMP_JACOBI 

Only returns singular values, but computes complete decomposition using GSL_THIN_DECOMP_JACOBI.

LAPACK_ONLY_DGESVD 

Lapack DGESVD divide and conquer method (only compute singular values, more efficient than complete decomposition);

LAPACK_ONLY_DGESDD 

Lapack DGESDD method (only compute singular values, more efficient than complete decomposition);

Definition at line 87 of file qvmatrixalgebra.h.

Available methods for Cholesky Decomposition.

Enumerator:
GSL_CHOLESKY 

GSL Cholesky method;

LAPACK_CHOLESKY_DPOTRF 

Lapack DPOTRF method ;

Definition at line 97 of file qvmatrixalgebra.h.

Available methods for QR Decomposition.

Enumerator:
GSL_HOUSEHOLDER_THIN_QR 

GSL Householder QR method (thin);

GSL_HOUSEHOLDER_FULL_QR 

GSL Householder QR method (full);

LAPACK_THIN_DGEQR2 

Lapack DGEQR2 (unblocked QR) method (thin);

LAPACK_FULL_DGEQR2 

Lapack DGEQR2 (unblocked QR) method (full);

Definition at line 104 of file qvmatrixalgebra.h.

Available methods for LU Decomposition.

Enumerator:
GSL_LU 

GSL (Gauss elimination with partial pivoting method);

LAPACK_DGETRF 

Lapack DGETRF (Gauss elimination with partial pivoting);

Definition at line 113 of file qvmatrixalgebra.h.

Available methods for EigenDecomposition.

Enumerator:
GSL_EIGENSYMM 

GSL eigendecomposition of a real symmetric matrix (eigenvalues and eigenvectors);

LAPACK_DSYEV 

Lapack DSYEV eigendecomposition (eigenvalues and eigenvectors);

Definition at line 120 of file qvmatrixalgebra.h.

Available methods for EigenValues only computation.

Enumerator:
GSL_EIGENSYMM_ONLY 

GSL eigendecomposition of a real symmetric matrix (eigenvalues only);

LAPACK_DSYEV_ONLY 

Lapack DSYEV eigendecomposition (eigenvalues only);

Definition at line 127 of file qvmatrixalgebra.h.

Available methods for sparse linear system solving.

Enumerator:
QVMKL_DSS 

Intel MKL direct sparse solver.

QVMKL_ISS 

Intel MKL iterative sparse solver.

QVCHOLMOD_DSS 

CHOLMOD direct sparse solver.

QV_SCG 

Iterative sparse conjugate gradient.

QV_BJPCG 

Block Jacobian preconditioned conjugate gradient.

QV_DENSE 

Direct dense method.

Definition at line 134 of file qvmatrixalgebra.h.


Function Documentation

void singularValueDecomposition ( const QVMatrix M,
QVMatrix U,
QVVector s,
QVMatrix V,
const TQVSVD_Method  method = DEFAULT_TQVSVD_METHOD 
)

Obtains the Singular Value Decomposition (SVD) of a rectangular $ m \times n $ matrix M.

The SV decomposition obtains two matrices U and V and a vector s from an original matrix M satisfying the following equation:

$ M = U diag(s) V^T $

If the decomposition method is 'full', both U and V are square matrices of sizes $ m \times m $ and $ n \times n $, respectively, while the $diag(s)$ matrix is of size $ m \times n $, with all values zero, except on values $s(i)$ on its main diagonal, which correspond to the singular values in decreasing order.

If the decomposition is 'thin', then U and V are only of sizes $ m \times \min(m,n) $ and $ \min(m,n) \times n $, while the $diag(s)$ matrix is square of size $ \min(m,n) \times \min(m,n) $, and containing the singular values in decreasing order in the elements of its diagonal.

In any case, both matrices U and V have always orthonormal columns (that is, $ U^T U = I $ and $ V^T V = I $ ), and if the decomposition method is 'full', are fully orthogonal square matrices.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input matrix to decompose
U param to store the matrix U from the SVD decomposition (overwritten on output)
s param to store the s vector of singular values from the SVD decomposition (overwritten on output)
V param to store the matrix V from the SVD decomposition (overwritten on output)
method method to use in the computation (see TQVSVD_Method)
See also:
solveFromSingularValueDecomposition solveBySingularValueDecomposition

Definition at line 204 of file qvmatrixalgebra.cpp.

Referenced by computeProjectiveHomography(), getCameraPosesFromEssentialMatrix(), pseudoInverse(), and solveHomogeneous().

void solveFromSingularValueDecomposition ( const QVMatrix U,
const QVVector s,
const QVMatrix V,
QVMatrix X,
const QVMatrix B 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained singular value decomposition $M = U diag(s) V^T$.

The solution is obtained with the following expression:

$ X = V diag(s)^{-1} U^T B $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
U input matrix U from the SVD decomposition of M
s input vector of singular values from the SVD decomposition of M
V input matrix V from the SVD decomposition of M
X unknown matrix (overwritten on output)
B input right hand side matrix
See also:
singularValueDecomposition solveBySingularValueDecomposition

Definition at line 224 of file qvmatrixalgebra.cpp.

Referenced by solveBySingularValueDecomposition(), and solveFromSingularValueDecomposition().

void solveFromSingularValueDecomposition ( const QVMatrix U,
const QVVector s,
const QVMatrix V,
QVVector x,
const QVVector b 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained singular value decomposition $M = U diag(s) V^T$.

The solution is obtained with the following expression:

$ x = V diag(s)^{-1} U^T b $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
U input matrix U from the SVD decomposition of M
s input vector of singular values from the SVD decomposition of M
V input matrix V from the SVD decomposition of M
x unknown vector (overwritten on output)
b input right hand side vector
See also:
solveFromSingularValueDecomposition(const QVMatrix &, const QVVector &, const QVMatrix &, QVMatrix &, const QVMatrix &)

Definition at line 241 of file qvmatrixalgebra.cpp.

void solveBySingularValueDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
const TQVSVD_Method  method = DEFAULT_TQVSVD_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the singular value decomposition $M = U diag(s) V^T$.

The solution is obtained by computing the singular value decomposition of $M$:

$ M = U diag(s) V^T $

And then using the following expression

$ X = V diag(s)^{-1} U^T B $.

Being $m \times n$ the size of the coefficient matrix $M$:

  • For overdetermined systems ($m>n$), the obtained solution minimizes the sums of squares of the residuals of the $m$ equations.
  • For sub-determined systems ($m<n$), the obtained solution has minimum norm amongst all the valid solutions.
Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
method method to use in the SVD computation (see TQVSVD_Method)
See also:
singularValueDecomposition solveFromSingularValueDecomposition

Definition at line 260 of file qvmatrixalgebra.cpp.

void solveBySingularValueDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
const TQVSVD_Method  method = DEFAULT_TQVSVD_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the singular value decomposition $M = U diag(s) V^T$.

The solution is obtained by computing the singular value decomposition of $M$:

$ M = U diag(s) V^T $

And then using the following expression

$ x = V diag(s)^{-1} U^T b $.

Being $m \times n$ the size of the coefficient matrix $M$:

  • For overdetermined systems ($m>n$), the obtained solution minimizes the sums of squares of the residuals of the $m$ equations.
  • For sub-determined systems ($m<n$), the obtained solution has minimum norm amongst all the valid solutions.
Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x unknown vector (overwritten on output)
b input right hand side vector
See also:
void solveBySingularValueDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVSVD_Method);

Definition at line 250 of file qvmatrixalgebra.cpp.

Referenced by QVMatrix::matrixDivide().

void solveBySingularValueDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
QVMatrix U,
QVVector s,
QVMatrix V,
const TQVSVD_Method  method = DEFAULT_TQVSVD_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the singular value decomposition $M = U diag(s) V^T$.

The solution is obtained by computing the singular value decomposition of $M$:

$ M = U diag(s) V^T $

And then using the following expression

$ X = V diag(s)^{-1} U^T B $.

The function also returns the matrices $ U$ and $ V$, and the vector $ s$ resulting from the singular value decomposition.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
U param to store the matrix U resulting from the singular value decomposition (overwritten on output)
s param to store the vector s resulting from the singular value decomposition (overwritten on output)
V param to store the matrix V resulting from the singular value decomposition (overwritten on output)
See also:
void solveBySingularValueDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVSVD_Method)

Definition at line 280 of file qvmatrixalgebra.cpp.

void solveBySingularValueDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
QVMatrix U,
QVVector s,
QVMatrix V,
const TQVSVD_Method  method = DEFAULT_TQVSVD_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the singular value decomposition $M = U diag(s) V^T$.

The solution is obtained by computing the singular value decomposition of $M$:

$ M = U diag(s) V^T $

And then using the following expression

$ x = V diag(s)^{-1} U^T b $.

The function also returns the matrices $ U$ and $ V$, and the vector $ s$ resulting from the singular value decomposition.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient vector
x unknown vector (overwritten on output)
b input right hand side vector
U param to store the matrix U resulting from the singular value decomposition (overwritten on output)
s param to store the vector s resulting from the singular value decomposition (overwritten on output)
V param to store the matrix V resulting from the singular value decomposition (overwritten on output)
See also:
void solveBySingularValueDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVSVD_Method);

Definition at line 269 of file qvmatrixalgebra.cpp.

double singularValueDecompositionResidual ( const QVMatrix M,
const QVMatrix U,
const QVVector s,
const QVMatrix V 
)

Checks for correctness of the SVD of a matrix.

This function computes the value $||U diag(s) V^T-M)||_{Frobenius} + ||V^T V - I||_{Frobenius} + ||U^T U - I||_{Frobenius}$, which should be close to zero if $ M = U diag(s) V^T $ is a correct SVD of matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input M matrix
U input U matrix from the SVD decomposition of M
s input vector of singular values from the SVD decomposition of M
V input V matrix from the SVD decomposition of M
See also:
singularValueDecomposition

Definition at line 287 of file qvmatrixalgebra.cpp.

void singularValues ( const QVMatrix M,
QVVector s,
const TQVSV_Method  method = DEFAULT_TQVSV_METHOD 
)

Gets the singular values of a matrix.

This function computes only the singular values of a matrix (which, depending on the used method, will be much faster than performing a full decomposition).

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input M matrix
s vector of singular values from the SVD decomposition (overwritten on output)
method method to use in the SV computation (see TQVSV_Method)
See also:
singularValueDecomposition

Definition at line 304 of file qvmatrixalgebra.cpp.

double singularValuesResidual ( const QVMatrix M,
const QVVector s 
)

Checks for correctness of the singular values of a matrix.

This function computes the value $||M||^2_{Frobenius} - ||s||^2$, which should be close to zero if $s$ are the singular values of M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input M matrix
s input vector of singular values from the SVD decomposition of M
See also:
SingularValues

Definition at line 321 of file qvmatrixalgebra.cpp.

void CholeskyDecomposition ( const QVMatrix M,
QVMatrix L,
const TQVCholesky_Method  method = DEFAULT_TQVCHOLESKY_METHOD 
)

Obtains the Cholesky decomposition of a symmetric and positive definite matrix.

The Cholesky decomposition obtains a lower triangular matrix L with strictly positive diagonal entries from an original matrix M, satisfying the following equation:

$ M = L L^{T} $

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M param containing the matrix to decompose
L param to store the resulting matrix L from the Cholesky decomposition (overwritten on output)
method method to use in the computation (see TQVCholesky_Method)
Note:
Matrix M must be symmetric. More precisely, the GSL_CHOLESKY method will only use the lower triangular part of M as input, while the LAPACK_CHOLESKY_DPOTRF method will only use the upper triangular part (the rest of the matrix will not be read in any of both cases, because M is supposed to be symmetric).
Matrix M must also be positive definite. Otherwise, problems will arise: the GSL_CHOLESKY will fail and abort the program, while the LAPACK_CHOLESKY_DPOTRF will have an undefined behavior.
See also:
solveFromCholeskyDecomposition solveByCholeskyDecomposition

Definition at line 382 of file qvmatrixalgebra.cpp.

void solveFromCholeskyDecomposition ( const QVMatrix L,
QVMatrix X,
const QVMatrix B 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained Cholesky decomposition $ M = L L^{T} $.

The matrix $ M $ must be a symmetric positive definite matrix. The two resultant triangular systems on $L$ and $L^T$ are solved by back-substitution to solve the linear system.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
L input matrix from the Cholesky decomposition of M
X unknown matrix (overwritten on output)
B input right hand side matrix
See also:
CholeskyDecomposition solveByCholeskyDecomposition

Definition at line 387 of file qvmatrixalgebra.cpp.

Referenced by solveByCholeskyDecomposition(), and solveFromCholeskyDecomposition().

void solveFromCholeskyDecomposition ( const QVMatrix L,
QVVector x,
const QVVector b 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained Cholesky decomposition $ M = L L^{T} $.

The matrix $ M $ must be a symmetric positive definite matrix. The two resultant triangular systems on $L$ and $L^T$ are solved by back-substitution to solve the linear system.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
L input matrix from the Cholesky decomposition of M
x unknown vector (overwritten on output)
b input right hand side vector
See also:
solveFromCholeskyDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &)

Definition at line 394 of file qvmatrixalgebra.cpp.

void solveByCholeskyDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
const TQVCholesky_Method  method = DEFAULT_TQVCHOLESKY_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the Cholesky decomposition $ M = L L^{T} $.

The matrix $ M $ must be a symmetric positive definite matrix. The two resultant triangular systems on $L$ and $L^T$ are solved by back-substitution to obtain the unknown matrix X.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
method method to use in the SVD computation (see TQVCholesky_Method)
See also:
CholeskyDecomposition solveFromCholeskyDecomposition

Definition at line 403 of file qvmatrixalgebra.cpp.

Referenced by optimizeReprojectionErrorFor3DPoint(), optimizeReprojectionErrorForCameraPose(), optimizeReprojectionErrorForCameraPoseCauchy(), and sparseSolve().

void solveByCholeskyDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
const TQVCholesky_Method  method = DEFAULT_TQVCHOLESKY_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the Cholesky decomposition $ M = L L^{T} $.

The matrix $ M $ must be a symmetric positive definite matrix. The two resultant triangular systems on $L$ and $L^T$ are solved by back-substitution to obtain the unknown vector x.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x unknown vector (overwritten on output)
b input right hand side vector
See also:
void solveByCholeskyDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVCholesky_Method)

Definition at line 412 of file qvmatrixalgebra.cpp.

void solveByCholeskyDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
QVMatrix L,
const TQVCholesky_Method  method = DEFAULT_TQVCHOLESKY_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the Cholesky decomposition $ M = L L^{T} $.

The matrix $ M $ must be a symmetric positive definite matrix. The two resultant triangular systems on $L$ and $L^T$ are solved by back-substitution to obtain the unknown matrix X.

The matrix $ L$ resulting from the Cholesky decomposition is also returned.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
L param to store the matrix L resulting from the Cholesky decomposition (overwritten on output)
See also:
void solveByCholeskyDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVCholesky_Method)

Definition at line 422 of file qvmatrixalgebra.cpp.

void solveByCholeskyDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
QVMatrix L,
const TQVCholesky_Method  method = DEFAULT_TQVCHOLESKY_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the Cholesky decomposition $ M = L L^{T} $.

The matrix $ M $ must be a symmetric positive definite matrix. The two resultant triangular systems on $L$ and $L^T$ are solved by back-substitution to obtain the unknown matrix X.

The matrix $ L$ resulting from the Cholesky decomposition is also returned.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x unknown vector (overwritten on output)
b input right hand side vector
L param to store the matrix L resulting from the Cholesky decomposition (overwritten on output)
See also:
void solveByCholeskyDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVCholesky_Method)

Definition at line 430 of file qvmatrixalgebra.cpp.

double CholeskyDecompositionResidual ( const QVMatrix M,
const QVMatrix L 
)

Checks for correctness of the Cholesky decomposition of a matrix.

This function computes the value $||L L^T-M)||_{Frobenius}$, which should be close to zero if $ M = L L^T $ is a correct Cholesky decomposition of matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input matrix
L input matrix from the Cholesky decomposition of M
See also:
CholeskyDecomposition

Definition at line 441 of file qvmatrixalgebra.cpp.

void LUDecomposition ( const QVMatrix M,
QVMatrix P,
QVMatrix L,
QVMatrix U,
const TQVLU_Method  method = DEFAULT_TQVLU_METHOD 
)

Obtains the LU decomposition of a rectangular $ m \times n $ matrix.

The LU decomposition obtains three matrices: P L, and U from an original matrix M, satisfying the following equation:

$ M = P L U $

Being the original matrix M of size $ m \times n $, result matrices L and U are lower and upper triangular matrices of sizes $ m \times min(m,n) $ and $ min(m,n) \times n $ respectively, while P is a square $ m \times m $ permutation matrix (in which each row and column have one and only one value equal to one, the rest of values being zeros).

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M param containing the matrix to decompose
P param to store the matrix P resulting from the LU decomposition (overwritten on output)
L param to store the matrix L resulting from the LU decomposition (overwritten on output)
U param to store the matrix U resulting from the LU decomposition (overwritten on output)
method method to use in the computation (see TQVLU_Method)
Note:
The GSL_LU method only accepts a square matrix ($ m = n$) as input, otherwise it will fail and abort the program showing an adequate message. The LAPACK_DGETRF is more general, and accepts general rectangular $ m \times n $ matrices.
See also:
solveFromLUDecomposition solveByLUDecomposition

Definition at line 552 of file qvmatrixalgebra.cpp.

Referenced by determinant().

void solveFromLUDecomposition ( const QVMatrix P,
const QVMatrix L,
const QVMatrix U,
QVMatrix X,
const QVMatrix B 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained LU decomposition of M:

$ M = P L U $

The solution for the linear system is obtained by solving the two resultant triangular systems on $L$ and $U$ by back-substitution, while permuting the elements according to $ P $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
P input matrix from the LU decomposition of M
L input matrix from the LU decomposition of M
U input matrix from the LU decomposition of M
X unknown matrix (overwritten on output)
B input right hand side matrix
See also:
LUDecomposition solveByLUDecomposition

Definition at line 557 of file qvmatrixalgebra.cpp.

Referenced by solveByLUDecomposition(), and solveFromLUDecomposition().

void solveFromLUDecomposition ( const QVMatrix P,
const QVMatrix L,
const QVMatrix U,
QVVector x,
const QVVector b 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained LU decomposition $ M = P L U $.

The solution for the linear system is obtained by solving the two resultant triangular systems on $L$ and $U$ by back-substitution, while permuting the elements according to $ P $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
P input matrix from the LU decomposition of M
L input matrix from the LU decomposition of M
U input matrix from the LU decomposition of M
x unknown vector (overwritten on output)
b input right hand side vector
See also:
void solveFromLUDecomposition(const QVMatrix &, const QVMatrix &, const QVMatrix &, QVMatrix &, const QVMatrix &)

Definition at line 578 of file qvmatrixalgebra.cpp.

void solveByLUDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
const TQVLU_Method  method = DEFAULT_TQVLU_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the LU decomposition $ M = P L U $.

The solution for the linear system is obtained by solving the two resultant triangular systems on $L$ and $U$ by back-substitution, while permuting the elements according to $ P $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
method method to use in the LU decomposition (see TQVLU_Method)
Note:
The GSL_LU method only accepts a square system ($ m = n$) as input, otherwise it will fail and abort the program showing an adequate message. The LAPACK_DGETRF is more general, and accepts general rectangular $ m \times n $ system, if m<n (sub-determined). In this case, the solution vector obtained has n-m zeros in the last n-m positions. LU decomposition is not adequate in any case for solving overdetermined systems of equations (m>n). Use solveBySingularValueDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVSVD_Method) or solveByQRDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVQR_Method) instead for solving this type of systems in the minimum squares sense.
See also:
LUDecomposition solveFromLUDecomposition

Definition at line 587 of file qvmatrixalgebra.cpp.

void solveByLUDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
const TQVLU_Method  method = DEFAULT_TQVLU_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the LU decomposition $ M = P L U $.

The solution for the linear system is obtained by solving the two resultant triangular systems on $L$ and $U$ by back-substitution, while permuting the elements according to $ P $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x unknown vector (overwritten on output)
b input right hand side vector
method method to use in the LU decomposition (see TQVLU_Method)
Note:
The GSL_LU method only accepts a square system ($ m = n$) as input, otherwise it will fail and abort the program showing an adequate message. The LAPACK_DGETRF is more general, and accepts general rectangular $ m \times n $ system, if m<n (sub-determined). In this case, the solution vector obtained has n-m zeros in the last n-m positions. LU decomposition is not adequate in any case for solving overdetermined systems of equations (m>n). Use solveBySingularValueDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVSVD_Method) or solveByQRDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVQR_Method) instead for solving this type of systems in the minimum squares sense.
See also:
void solveByLUDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVLU_Method)

Definition at line 595 of file qvmatrixalgebra.cpp.

void solveByLUDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
QVMatrix P,
QVMatrix L,
QVMatrix U,
const TQVLU_Method  method = DEFAULT_TQVLU_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the LU decomposition $ M = P L U $.

The solution for the linear system is obtained by solving the two resultant triangular systems on $L$ and $U$ by back-substitution, while permuting the elements according to $ P $.

The function also returns the matrices $ P$, $ L$, and $ U$ resulting from the LU decomposition.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
P param to store the matrix P resulting from the LU decomposition (overwritten on output)
L param to store the matrix L resulting from the LU decomposition (overwritten on output)
U param to store the matrix U resulting from the LU decomposition (overwritten on output)
method method to use in the LU decomposition (see TQVLU_Method)
Note:
The GSL_LU method only accepts a square system ($ m = n$) as input, otherwise it will fail and abort the program showing an adequate message. The LAPACK_DGETRF is more general, and accepts general rectangular $ m \times n $ system, if m<n (sub-determined). In this case, the solution vector obtained has n-m zeros in the last n-m positions. LU decomposition is not adequate in any case for solving overdetermined systems of equations (m>n). Use solveBySingularValueDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVSVD_Method) or solveByQRDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVQR_Method) instead for solving this type of systems in the minimum squares sense.
See also:
void solveByLUDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVLU_Method)

Definition at line 605 of file qvmatrixalgebra.cpp.

void solveByLUDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
QVMatrix P,
QVMatrix L,
QVMatrix U,
const TQVLU_Method  method = DEFAULT_TQVLU_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the LU decomposition $ M = P L U $.

The solution for the linear system is obtained by solving the two resultant triangular systems on $L$ and $U$ by back-substitution, while permuting the elements according to $ P $.

The function also returns the matrices $ P$, $ L$, and $ U$ resulting from the LU decomposition.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x unknown vector (overwritten on output)
b input right hand side vector
P param to store the matrix P resulting from the LU decomposition (overwritten on output)
L param to store the matrix L resulting from the LU decomposition (overwritten on output)
U param to store the matrix U resulting from the LU decomposition (overwritten on output)
Note:
The GSL_LU method only accepts a square system ($ m = n$) as input, otherwise it will fail and abort the program showing an adequate message. The LAPACK_DGETRF is more general, and accepts general rectangular $ m \times n $ system, if m<n (sub-determined). In this case, the solution vector obtained has n-m zeros in the last n-m positions. LU decomposition is not adequate in any case for solving overdetermined systems of equations (m>n). Use solveBySingularValueDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, TQVSVD_Method) or solveByQRDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVQR_Method) instead for solving this type of systems in the minimum squares sense.
See also:
void solveByLUDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVLU_Method)

Definition at line 613 of file qvmatrixalgebra.cpp.

double LUDecompositionResidual ( const QVMatrix M,
const QVMatrix P,
const QVMatrix L,
const QVMatrix U 
)

Checks for correctness of the LU decomposition of a matrix.

This function computes the value $||P L U - M)||_{Frobenius}$, which should be close to zero if $ M = P L U $ is a correct LU decomposition of matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input matrix
P input matrix from the LU decomposition of M
L input matrix from the LU decomposition of M
U input matrix from the LU decomposition of M
See also:
LUDecomposition

Definition at line 624 of file qvmatrixalgebra.cpp.

void QRDecomposition ( const QVMatrix M,
QVMatrix Q,
QVMatrix R,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Obtains the QR decomposition of a rectangular $ m \times n $ matrix.

The QR decomposition obtains two matrices Q and R from an original matrix M of size $ m \times n $ that satisfy the following equation:

$ M = Q R $

For a square matrix M (m=n), Q is orthogonal and R is upper triangular, both square of size $ m \times m$ = $ n \times n $.

For full decomposition methods, or if m<n, matrix Q is orthogonal of size $ m \times m $ and R is an upper triangular matrix of size $ m \times n $.

For thin decomposition methods, and if m>n, matrix Q has size $ m \times n $, with orthogonal columns, and R is an upper triangular matrix of size $ n \times n $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M param containing the matrix to decompose
Q param to store the resulting matrix Q from the QR decomposition (overwritten on output)
R param to store the resulting matrix R from the QR decomposition (overwritten on output)
method method to use in the computation (see TQVQR_Method)
See also:
QLDecomposition LQDecomposition RQDecomposition solveFromQRDecomposition solveByQRDecomposition

Definition at line 761 of file qvmatrixalgebra.cpp.

double QRDecompositionResidual ( const QVMatrix M,
const QVMatrix Q,
const QVMatrix R 
)

Checks for correctness of the QR decomposition of a matrix.

This function computes the value $||Q R - M)||_{Frobenius} + ||Q^T Q - I)||_{Frobenius}$, which should be close to zero if $ M = Q R $ is a correct QR decomposition of matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input matrix
Q input matrix from the QR decomposition of M
R input matrix from the QR decomposition of M
See also:
QRDecomposition

Definition at line 766 of file qvmatrixalgebra.cpp.

void QLDecomposition ( const QVMatrix M,
QVMatrix Q,
QVMatrix L,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Obtains the QL decomposition of a rectangular $ m \times n $ matrix.

The QL decomposition obtains two matrices Q and L from an original matrix M of size $ m \times n $ that satisfy the following equation:

$ M = Q L $

For a square matrix M (m=n), Q is orthogonal and L is lower triangular,both square of size $ m \times m$ = $ n \times n $.

If m>n, then thin decomposition methods obtain a Q matrix of size $ m \times n $, with orthogonal columns, and a matrix L which is a lower triangular matrix of size $ n \times n $, while full decomposition methods obtain a matrix Q orthogonal of size $ m \times m $ and a matrix L of size $ m \times n $ whose first m-n rows are zero, and whose last n rows form a lower triangular matrix.

If m<n, then both full and thin decomposition methods obtain a matrix Q orthogonal of size $ m \times m $ and a matrix L of size $ m \times n $ whose first m-n cols are in general not zero and whose last n columns form a lower triangular matrix.

This function uses the underlying function QRDecomposition to perform the QL decomposition, so the available methods are the same than the ones used in the QR decomposition (see TQVQR_Method).

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M param containing the matrix to decompose
Q param to store the matrix Q resulting from the QL decomposition (overwritten on output)
L param to store the matrix L resulting from the QL decomposition (overwritten on output)
method method to use in the computation (see TQVQR_Method)
See also:
QRDecomposition LQDecomposition RQDecomposition

Definition at line 771 of file qvmatrixalgebra.cpp.

double QLDecompositionResidual ( const QVMatrix M,
const QVMatrix Q,
const QVMatrix L 
)

Checks for correctness of the QL decomposition of a matrix.

This function computes the value $||Q L - M)||_{Frobenius} + ||Q^T Q - I)||_{Frobenius}$, which should be close to zero if $ M = Q L $ is a correct QL decomposition of matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input matrix
Q input matrix from the QL decomposition of M
L input matrix from the QL decomposition of M
See also:
QLDecomposition

Definition at line 784 of file qvmatrixalgebra.cpp.

void RQDecomposition ( const QVMatrix M,
QVMatrix R,
QVMatrix Q,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Obtains the RQ decomposition of a rectangular $ m \times n $ matrix.

The RQ decomposition obtains two matrices R and Q from an original matrix M of size $ m \times n $ that satisfy the following equation:

$ M = R Q $

For a square matrix M (m=n), R is upper triangular and Q orthogonal, both square of size $ m \times m$ = $ n \times n $.

If m>n, then both full and thin decomposition methods obtain a matrix R of size $ m \times n $ whose first m-n rows are in general not zero and whose last n rows form an upper triangular matrix, and a matrix Q which is orthogonal of size $ n \times n $.

If m<n, then thin decomposition methods obtain a matrix R which is an upper triangular matrix of size $ m \times m $ and a Q matrix of size $ m \times n $, with orthogonal rows, while full decomposition methods obtain a matrix R of size $ m \times n $ whose first n-m columns are zero, and whose last m columns form a lower triangular matrix, and a matrix Q orthogonal of size $ n \times n $.

This function uses the underlying function QRDecomposition to perform the RQ decomposition, so the available methods are the same than the ones used in the QR decomposition (see TQVQR_Method).

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M param containing the matrix to decompose
R param to store the matrix R resulting from the RQ decomposition (overwritten on output)
Q param to store the matrix Q resulting from the RQ decomposition (overwritten on output)
method method to use in the computation (see TQVQR_Method)
See also:
QRDecomposition QLDecomposition LQDecomposition

Definition at line 789 of file qvmatrixalgebra.cpp.

double RQDecompositionResidual ( const QVMatrix M,
const QVMatrix R,
const QVMatrix Q 
)

Checks for correctness of the RQ decomposition of a matrix.

This function computes the value $||R Q - M)||_{Frobenius} + ||Q Q^T - I)||_{Frobenius}$, which should be close to zero if $ M = R Q $ is a correct RQ decomposition of matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input matrix
R input matrix from the RQ decomposition of M
Q input matrix from the RQ decomposition of M
See also:
RQDecomposition

Definition at line 802 of file qvmatrixalgebra.cpp.

void LQDecomposition ( const QVMatrix M,
QVMatrix L,
QVMatrix Q,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Obtains the LQ decomposition of a rectangular $ m \times n $ matrix.

The LQ decomposition obtains two matrices L and Q from an original matrix M of size $ m \times n $ that satisfy the following equation:

$ M = L Q $

For a square matrix M (m=n), L is lower triangular and Q orthogonal, both square of size $ m \times m$ = $ n \times n $.

For full decomposition methods, or if m>n, L is a lower triangular matrix of size $ m \times n $ and matrix Q is orthogonal of size $ n \times n $ .

For thin decomposition methods, and if m<n, L is a lower triangular matrix of size $ m \times m $, and matrix Q has size $ m \times n $, with orthogonal rows.

This function uses the underlying function QRDecomposition to perform the LQ decomposition, so the available methods are the same than the ones used in the QR decomposition (see TQVQR_Method).

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M param containing the matrix to decompose
L param to store the matrix L resulting from the LQ decomposition (overwritten on output)
Q param to store the matrix Q resulting from the LQ decomposition (overwritten on output)
method method to use in the computation (see TQVQR_Method)
See also:
QRDecomposition QLDecomposition RQDecomposition

Definition at line 807 of file qvmatrixalgebra.cpp.

double LQDecompositionResidual ( const QVMatrix M,
const QVMatrix L,
const QVMatrix Q 
)

Checks for correctness of the LQ decomposition of a matrix.

This function computes the value $||L Q - M)||_{Frobenius} + ||Q Q^T - I)||_{Frobenius}$, which should be close to zero if $ M = L Q $ is a correct LQ decomposition of matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input matrix
L input matrix from the LQ decomposition of M
Q input matrix from the LQ decomposition of M
See also:
LQDecomposition

Definition at line 820 of file qvmatrixalgebra.cpp.

void solveFromQRDecomposition ( const QVMatrix Q,
const QVMatrix R,
QVMatrix X,
const QVMatrix B 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the previously obtained QR decomposition of M:

$ M X = Q R $

The solution is obtained by solving the triangular system $ R X = Q^T B $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
Q input matrix Q from the QR decomposition of M
R input matrix R from the QR decomposition of M
X unknown matrix (overwritten on output)
B input right hand side matrix
See also:
QRDecomposition solveByQRDecomposition

Definition at line 825 of file qvmatrixalgebra.cpp.

Referenced by solveByQRDecomposition(), and solveFromQRDecomposition().

void solveFromQRDecomposition ( const QVMatrix Q,
const QVMatrix R,
QVVector x,
const QVVector b 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the previously obtained QR decomposition of M:

$ M = Q R $

The solution is obtained by solving the triangular system $ R X = Q^T B $.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
Q input matrix Q from the QR decomposition of M
R input matrix R from the QR decomposition of M
x unknown vector (overwritten on output)
b input right hand side vector
See also:
void solveFromQRDecomposition(const QVMatrix &, const QVMatrix &, QVMatrix &, const QVMatrix &)

Definition at line 846 of file qvmatrixalgebra.cpp.

void solveByQRDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the QR decomposition of M:

$ M = Q R $

The solution is obtained by solving the triangular system $ R X = Q^T B $.

Note:
For overdetermined systems ($m>n$, being $m \times n$ the size of the coefficient matrix $M$), the obtained solution minimizes the sums of squares of the residuals of the $m$ equations.
Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
method method to use in the QR computation (see TQVQR_Method)
See also:
QRDecomposition solveFromQRDecomposition

Definition at line 864 of file qvmatrixalgebra.cpp.

void solveByQRDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the QR decomposition of M:

$ M = Q R $

The solution is obtained by solving the triangular system $ R X = Q^T B $.

Note:
For overdetermined systems ($m>n$, being $m \times n$ the size of the coefficient matrix $M$), the obtained solution minimizes the sums of squares of the residuals of the $m$ equations.
Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x unknown vector (overwritten on output)
b input right hand side vector
See also:
void solveByQRDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVQR_Method)

Definition at line 855 of file qvmatrixalgebra.cpp.

void solveByQRDecomposition ( const QVMatrix M,
QVMatrix X,
const QVMatrix B,
QVMatrix Q,
QVMatrix R,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Solves the linear system $M X = B$ for the unknown matrix $X$, using the QR decomposition of M:

$ M = Q R $

The solution is obtained by solving the triangular system $ R X = Q^T B $. The function also returns the matrices $ Q$ and $ R$ resulting from the QR decomposition.

Note:
For overdetermined systems ($m>n$, being $m \times n$ the size of the coefficient matrix $M$), the obtained solution minimizes the sums of squares of the residuals of the $m$ equations.
Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X unknown matrix (overwritten on output)
B input right hand side matrix
Q param to store the matrix Q resulting from the QR decomposition (overwritten on output)
R param to store the matrix R resulting from the QR decomposition (overwritten on output)
See also:
void solveByQRDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVQR_Method)

Definition at line 882 of file qvmatrixalgebra.cpp.

void solveByQRDecomposition ( const QVMatrix M,
QVVector x,
const QVVector b,
QVMatrix Q,
QVMatrix R,
const TQVQR_Method  method = DEFAULT_TQVQR_METHOD 
)

Solves the linear system $M x = b$ for the unknown vector $x$, using the QR decomposition of M:

$ M = Q R $

The solution is obtained by solving the triangular system $ R X = Q^T B $. The function also returns the matrices $ Q$ and $ R$ resulting from the QR decomposition.

Note:
For overdetermined systems ($m>n$, being $m \times n$ the size of the coefficient matrix $M$), the obtained solution minimizes the sums of squares of the residuals of the $m$ equations.
Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x unknown vector (overwritten on output)
b input right hand side vector
Q param to store the matrix Q resulting from the QR decomposition (overwritten on output)
R param to store the matrix R resulting from the QR decomposition (overwritten on output)
See also:
void solveByQRDecomposition(const QVMatrix &, QVMatrix &, const QVMatrix &, const TQVQR_Method)

Definition at line 872 of file qvmatrixalgebra.cpp.

void eigenDecomposition ( const QVMatrix M,
QVVector lambda,
QVMatrix Q,
const TQVEigenDecomposition_Method  method = DEFAULT_TQVEIGENDECOMPOSITION_METHOD 
)

Obtains the eigen-decomposition of a symmetric matrix.

The eigen-decomposition obtains the factorization of a symmetric matrix M into a canonical form, represented in terms of a set of eigenvectors and their corresponding eigenvalues.

Each eigenvector $ \mathbf{v}_i $ and its corresponding eigenvalue $ \lambda_i $ satisfy the following equation.

$ M \mathbf{v}_i = \lambda_i \mathbf{v}_i $

This function returns the eigenvectors and their corresponding eigenvalues in a Q matrix and a lambda vector, respectively. Each eigenvector is stored as a row of the Q matrix. The i-th element of the vector lambda contains the eigenvalue corresponding to the eigenvector stored in the i-th row. Eigenvectors are mutually orthogonal, therefore, Q is an orthonormal matrix (i.e. $ Q Q^T = Q^T Q = I $)

Thus, the following equation holds, given that the matrix $ Q $ and the vector $ \vec{\lambda} $ contain respectively the eigen-vectors and the eigen-values of the symmetric matrix M:

$ M = Q diag(\vec{\lambda}) Q^{T} $

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M symmetric matrix to obtain eigen-decomposition
lambda vector containing the eigenvalues from the eigen-decomposition (overwritten on output)
Q matrix containing the eigenvectors from the eigen-decomposition of M; eigenvectors are stored as row vectors (overwritten on output)
method method to use in the computation (see TQVEigenDecomposition_Method)

Definition at line 990 of file qvmatrixalgebra.cpp.

double eigenDecompositionResidual ( const QVMatrix M,
const QVVector lambda,
const QVMatrix Q 
)

Checks for correctness of the eigendecomposition of a matrix.

This function computes the value $||Q diag(\lambda) Q^T-M)||_{Frobenius} + ||Q^T Q - I||_{Frobenius}$, which should be close to zero if $ M = Q diag(\lambda) Q^T $ is a correct eigendecomposition of symmetric matrix M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input symmetric M matrix
lambda input vector of eigenvalues from the eigendecomposition of M
Q input Q matrix from the eigendecomposition of M
See also:
EigenDecomposition

Definition at line 995 of file qvmatrixalgebra.cpp.

void eigenValues ( const QVMatrix M,
QVVector lambda,
const TQVEigenValues_Method  method = DEFAULT_TQVEIGENVALUES_METHOD 
)

Gets the eigenvalues of a matrix.

This function computes only the eigenvalues of a symmetric matrix (which, depending also on the used method, will be much faster than performing a full eigendecomposition).

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input symmetric M matrix
lambda vector of eigenvalues from the eigendecomposition (overwritten on output)
method method to use in the eigenvalues computation (see TQVEigenValues_Method)
See also:
EigenDecomposition

Definition at line 1008 of file qvmatrixalgebra.cpp.

double eigenValuesResidual ( const QVMatrix M,
const QVVector lambda 
)

Checks for correctness of the eigenvalues of a symmetric matrix.

This function returns the difference between the sum of diagonal elements of the matrix (i.e., its trace) and the sum of the elements of $\lambda$ (which are supposed to be its eigenvalues). This should be close to zero if the $\lambda$ are really the eigenvalues of M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input M matrix
lambda input vector of eigenvalues from the eigendecomposition of M
See also:
EigenValues

Definition at line 1020 of file qvmatrixalgebra.cpp.

QVMatrix pseudoInverse ( const QVMatrix M,
const TQVSVD_Method  method = DEFAULT_TQVSVD_METHOD,
const double  epsilon = 1.0E-10 
)

Obtains the Moore–Penrose pseudoinverse of a matrix.

The pseudoinverse is computed using the SVD of the input matrix, and then using the reciprocal of the obtained singular values. The used formula is $ M^{+} = \sum_{i} (1/s_i) (v_i \otimes u_i) $, being $u_i$ and $v_i$ column vectors of the orthogonal U and V matrices obtained by SVD. Singular values which, when divided by the first singular value, are smaller than the epsilon parameter are discarded in the computation.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
A input matrix to obtain pseudoinverse
method method to use in the computation (see TQVSVD_Method)
epsilon singular values with value smaller than epsilon will be discarded in computation

Definition at line 1037 of file qvmatrixalgebra.cpp.

Referenced by computeAffineHomography(), correctIntrinsics(), QVMatrix::inverse(), linearCameraCenterResection(), and qvLinearRegularizedRegression().

double determinant ( const QVMatrix M,
const TQVLU_Method  method = DEFAULT_TQVLU_METHOD 
)

Obtains the determinant of a square matrix.

The determinant is obtained by first obtaining the LU decomposition of the matrix, then multiplying the values in the diagonal of U, and finally multiplying the result by the signature of the permutation P in the decomposition $ M = PLU $

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M matrix to obtain the determinant
method method to use in the LU decomposition (see TQVLU_Method)
Returns:
the value of the determinant

Definition at line 1057 of file qvmatrixalgebra.cpp.

Referenced by QVMatrix::det(), getCameraPosesFromEssentialMatrix(), and QVEuclideanMapping3::QVEuclideanMapping3().

void solveHomogeneous ( const QVMatrix A,
QVector< double > &  x,
const TQVSVD_Method  method = DEFAULT_TQVSVD_METHOD 
)

Solves an homogeneous linear system of equations.

Given a matrix M, this functions obtain the vector x satisfying the following equation:

$ M\mathbf{x} = \mathbf{0} $

The solution is based on the SVD decomposition of the matrix A. Vector x is set to the last column of the matrix V from the SVD decomposition of M.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M coeficient matrix for the homogeneous equation system.
x vector to store the solution.
method method to use in the SVD decomposition (see TQVSVD_Method)

Definition at line 1092 of file qvmatrixalgebra.cpp.

Referenced by linear3DPointTriangulation(), and linearCameraResection().

double solveResidual ( const QVMatrix M,
const QVMatrix X,
const QVMatrix B 
)

Returns the residual of the solution to a linear matrix equation.

This function computes the value $ ||M X - B||^2_{Frobenius} $, which should be close to zero if X is the solution to the matrix equation $ M X = B$, or should be minimized if the system was solved in the minimum squares sense.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
X input unknown matrix
B input right hand side matrix
Returns:
the computed residual
See also:
solveBySingularValueDecomposition solveByCholeskyDecomposition solveByLUDecomposition solveByQRDecomposition

Definition at line 1101 of file qvmatrixalgebra.cpp.

double solveResidual ( const QVMatrix M,
const QVVector x,
const QVVector b 
)

Returns the residual of the solution to a linear vector equation.

This function computes the value $||M x - B||^2 $, which should be close to zero if x is the solution to the equation $ M x = b$, or should be minimized if the system was solved in the minimum squares sense.

Warning:
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coefficient matrix
x input unknown vector
b input right hand side vector
Returns:
the computed residual
See also:
solveBySingularValueDecomposition solveByCholeskyDecomposition solveByLUDecomposition solveByQRDecomposition

Definition at line 1108 of file qvmatrixalgebra.cpp.

double sparseSolve ( const QVSparseBlockMatrix M,
QVVector x,
const QVVector b,
const bool  isSymmetric = false,
const bool  isPosDefinite = false,
const TQVSparseSolve_Method  method = DEFAULT_TQVSPARSESOLVE_METHOD,
const bool  start_from_x = false,
const bool  iters_or_resid = true,
const int  iters = 0,
const double  resid = 1.0E-10,
int &  final_iter_count = dummy 
)

Solves a sparse system of linear equations, taking advantage of sparseness to accelerate the computation.

Given a coefficient matrix M and an objective vector b, this functions obtains the vector x satisfying the following equation:

$ M\mathbf{x} = \mathbf{b} $

Warning:
Only upper-diagonal blocks should be defined in the input M matrix.
Either GSL or MKL compatibility must be enabled to use this function.
Parameters:
M input coeficient sparse block matrix in the matrix equation form of the problem (must be square)
x vector to store the solution (overwritten on output)
b input right-hand side vector in the matrix equation form of the problem
isSymmetric indicates if M must be considered symmetric (in this case, only the upper triangular part is taken into account, which will speed up the computation).
isPosDefinite indicates if M is positive definite (in this case, the solver will take this into account to speed up the computation).
method method to use in the computation (see TQVSparseSolve_Method)
start_from_x only for the QVMKL_ISS method, if true, start from the input value of x
iters_or_resid only for the QVMKL_ISS method, if true, use max iterations termination test (see param iters), otherwise use max residual (see param max_resid)
iters only for the incremental methods (QVMKL_ISS and QV_SCG). Number of iterations to execute (if zero, iterate until convergence or error)
max_resid only for the incremental methods (QVMKL_ISS and QV_SCG). Iterate until square of residual is below this parameter
iters only for the QVMKL_ISS method, final number of iterations really executed (overwritten on output)
Returns:
square norm of current residual, for incremental methods (QVMKL_ISS and QV_SCG), always 0.0 for QVMKL_DSS
See also:
QVSparseBlockMatrix

Definition at line 1216 of file qvmatrixalgebra.cpp.

Referenced by globalEpipolarAdjustment(), and incrementalGEA().

bool solveHomogeneous ( const QVSparseBlockMatrix A,
QVVector x,
const int  maxIterations = 10,
const double  minRelativeError = 0.0,
const TQVSparseSolve_Method  method = QVMKL_DSS 
)

Solves a sparse homogeneous linear system using the inverse iteration algorithm and the MKL sparse routines.

Given a matrix M, this function obtains the vector x satisfying the following equation:

$ M\mathbf{x} = \mathbf{0} $

An iterative process is used to converge from an initial random solution to the optimal solution of the equation.

Warning:
MKL compatibility must be enabled to use this function.
Parameters:
M input coeficient sparse block matrix in the matrix equation form of the problem (must be square)
x this vector will contain the solution to the homogeneous linear system in return. An initial approximation to the solution can be provided in this argument.
maxIterations number of maximal iterations to perform in the algoritm.
minRelativeError the iteration process will stop if the value $ \|x_i - x_{i-1} \| $ (the difference between the solutions obtained in the last two iterations) is smaller than this value.
method method to use in the computation (see TQVSparseSolve_Method). Only method QVMKL_DSS is currently implemented for this function.
See also:
QVSparseBlockMatrix
Note:
This function works only with MKL.

Definition at line 1629 of file qvmatrixalgebra.cpp.




QVision framework. PARP research group. Copyright © 2007, 2008, 2009, 2010, 2011.