The following methods are available for matrix decompositions and solution of simultaneous linear equations.

`1. T lud (valarray<size_t>& `*ri*, T* *pDet* = NULL);
2. void lubksb (const valarray<size_t>& *ri*, const valarray<T>& *v*, valarray<T>& *s*) const;
3. void lumpove (const matrix<T>& *ludm*, const valarray<size_t>& *ri*, const valarray<T>& *v*, valarray<T>& *s*) const;
4. bool solve_lu (const valarray<T>& *v*, valarray<T>& *s*) const;
5. bool svd (matrix<T>& *z*, valarray<T>& *w*);
6. void svbksb (const matrix<T>& *z*, const valarray<T>& *w*, const valarray<T>& *v*, valarray<T>& *s*) const;
7. bool solve_sv (const valarray<T>& v, valarray<T>& s) const;
8. void qrd (matrix<T>& *r*);
9. void qrbksb (const matrix<T>& *r*, const valarray<T>& *v*, valarray<T>& *s*) const;
10. bool solve_qr (const valarray<T>& v, valarray<T>& s) const;
11. bool chold ();
12. void cholbksb (const valarray<T>& *v*, valarray<T>& *s*) const;
13. bool solve_chol (const valarray<T>& v, valarray<T>& s) const;
14. bool inv ();
15. bool inv_lu ();
16. bool inv_sv ();
17. bool inv_qr ();
18. bool solve (const valarray<T>& *v*, valarray<T>& *s*) const;
19. bool solve (const matrix<T>& *v*, matrix<T>& *s*) const;

- Performs LU decomposition on a square matrix, i.e., the matrix A is decomposed as,
Where L is a lower triangular matrix and U is an upper triangular matrix. On decomposition, the matrix A is replaced by both L and U. The new changed row index is returned in the valarray#### A = L . U

*ri*for performing the back substitution later. It can also optionally copy the determinant of the matrix in the variable pointed to by*pDet*. It returns*true*on successful decomposition, and*false*if the matrix is non-square or singular. - Performs forward and back substitution on a LU decomposed matrix to find out the solution vector for a linear set of equations. Here,
*v*is the right hand side input vector and*ri*is the row index as returned by*lud*method. The solution vector will be returned in the vector*s*. - The
*lumpove*method can be used to improve an imperfect solutions found by LU decomposition method earlier. This method must be applied to the original matrix. Here,*ludm*is the LU decomposition of the original matrix,*v*is the right hand side vector and*ri*is the row index. The improved solution will be returned in the vector*s*. - The
*solve_lu*method solves a set of linear equations using LU decomposition method. Here*v*is the right hand side vector, and*s*is the reference to a valarray object to receive the solution vector*s*. Returns*true*if successful; otherwise, it returns*false*. - Performs Singular Value decomposition on a matrix, i.e., any M x N matrix A, where M >= N, is decomposed as,
Where#### A = U . W . Z

^{T}**U**is an M x N column-orthogonal matrix,**W**is a diagonal matrix, and**Z**is an N x N orthogonal matrix. After successful decomposition, the original matrix A is replaced by**U**, the diagonal matrix is returned in the vector*w*, and the orthogonal matrix in*z*. Returns*true*on successful decomposition, and*false*if there is no convergence after 30 iterations. - The
**svbksb**method performs back substitution on a SV decomposed matrix to find out the solution vector for a linear set of equations. Here the matrix*z*and vector*w*are as returned by the**svd**method,*v*is the right hand side vector, and*s*is the solution vector to be returned by this method. - The
*solve_sv*method solves a set of linear equations using SV decomposition method. Here*v*is the right hand side vector, and*s*is the reference to a valarray object to receive the solution vector*s*. Returns*true*if successful; otherwise, it returns*false*. - The QR decomposition method decomposes an M-by-N matrix A, where M >= N, into an M-by-N orthogonal matrix Q and an N-by-N upper triangular matrix R, i.e.,
After successful decomposition, the original matrix A is replaced by the orthogonal matrix#### A = Q . R

**Q**, and the upper triangular matrix*R*is returned in*r*. - Finds the solution vector for a QR decomposed matrix. Here
*r*is the upper triangular matrix returned by the**qrd**method,*v*is the right hand side vector, and*s*is the reference to a valarray class object to receive the solution vector. - The
*solve_qr*method solves a set of linear equations using QR decomposition method. Here*v*is the right hand side vector, and*s*is the reference to a valarray object to receive the solution vector*s*. Returns*true*if successful; otherwise, it returns*false*. - The Cholesky decomposition method
**chold**decomposes a symmetric, positive definite matrix A, into a lower triangular matrix L so that Returns#### A = L . L

^{T}*true*on success. If the matrix is not symmetric and positive definite, or singular, it returns*false*. - The
**cholbksb**method performs back substitution on a Cholesky decomposed matrix to find out the solution vector for a set of linear equations. Here*v*is the right hand side vector, and*s*is the reference to*valarray*object to receive the solution vector. - The
*solve_chol*solves a set of linear equations using Cholesky decomposition method. Here*v*is the right hand side vector, and*s*is the reference to a valarray object to receive the solution vector*s*. Returns*true*if successful; otherwise, it returns*false*. - Inverts the matrix. The matrix is inverted in-place using minimum memory, i.e., the original matrix is replaced by its inverse.
- Inverts the matrix. The matrix is inverted using LU decomposition method. The original matrix is replaced by its inverse. This method uses more memory than
**inv**and is also slightly slower. - Inverts the matrix. The matrix is inverted using SV decomposition method. The original matrix is replaced by its inverse.
- Inverts the matrix. The matrix is inverted using QR decomposition method. The original matrix is replaced by its inverse.
- Solves a set of linear equations using LU decomposition method. Here
*v*is the right hand side vector, and*s*is the reference to*valarray*object to receive the solution vector. Returns*true*is successful; otherwise, it returns*false*. - Solves a set of linear equations using LU decomposition method. The matrix
*v*may contain more than one the right hand side vector as column. For each right hand side vector, the solution vector is returned in the corresponding column of the matrix*s*. Returns*true*is successful; otherwise, it returns*false*.

```
typedef techsoft::matrix<double> Matrix;
typedef std::valarray<double> Vector;
using techsoft::gmslice;
using techsoft::LTRIANG;
Matrix A(5,5), Z(5,5);
Vector V(5), S(5), W(5);
std::valarray<size_t> ri;
std::cin >> A; // Reads the matrix from stdin
std::cin >> Z[0]; // Reads the vector from stdin
V = Z[0];
A.lud( ri);
A.lubksb( ri, V, S);
A = B;
A.svd( Z, W);
A.svbksb( Z, W, V, S);
A = B;
A.qrd( Z);
A.qrbksb( Z, V, S);
A = B[gmslice(LTRIANG)];
A[gmslice(LTRIANG)] = ~A; // A is now a symmetric matrix
A.chold();
A.cholbksb( V, S);
A = B;
A.inv(); // Inverts the matrix
A = B;
A.solve( V, S);
```