⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matdcmp.htm

📁 This matrix C++ template class library is for performing common matrix operations in your C++ progra
💻 HTM
字号:
<html>
<head>
  <link rel=stylesheet href="styles.css" type="text/css">
  <title>Matrix Decomposition Methods</title>
</head>
<body>

<h6 align=right>
<a href="logicop.htm">Prev</a> |
<a href="manual.htm">Up</a> |
<a href="matutil.htm">Next</a>
</h6>

<h2>Matrix Decomposition Methods</h2>

<p>
The following methods are available for matrix decompositions and solution of simultaneous linear equations.
</p>

<pre><code><a href="#u1">1</a>. T lud (valarray&lt;size_t&gt;&amp; <i>ri</i>);
<a href="#u2">2</a>. void lubksb (const valarray&lt;size_t&gt;&amp; <i>ri</i>, const valarray&lt;T&gt;&amp; <i>v</i>, valarray&lt;T&gt;&amp; <i>s</i>) const;
<a href="#u3">3</a>. void lumpove (const matrix&lt;T&gt;&amp; <i>ludm</i>, const valarray&lt;size_t&gt;&amp; <i>ri</i>, const valarray&lt;T&gt;&amp; <i>v</i>, valarray&lt;T&gt;&amp; <i>s</i>) const;

<a href="#u4">4</a>. void svd (matrix&lt;T&gt;&amp; <i>z</i>, valarray&lt;T&gt;&amp; <i>w</i>);
<a href="#u5">5</a>. void svbksb (const matrix&lt;T&gt;&amp; <i>z</i>, const valarray&lt;T&gt;&amp; <i>w</i>, const valarray&lt;T&gt;&amp; <i>v</i>, valarray&lt;T&gt;&amp; <i>s</i>) const;
   
<a href="#u6">6</a>. void qrd (matrix&lt;T&gt;&amp; <i>r</i>);
<a href="#u7">7</a>. void qrbksb (const matrix&lt;T&gt;&amp; <i>r</i>, const valarray&lt;T&gt;&amp; <i>v</i>, valarray&lt;T&gt;&amp; <i>s</i>) const;

<a href="#u8">8</a>. void chold ();
<a href="#u9">9</a>. void cholbksb (const valarray&lt;T&gt;&amp; <i>v</i>, valarray&lt;T&gt;&amp; <i>s</i>) const;

<a href="#u10">10</a>. void inv ();
<a href="#u11">11</a>. void inv2 ();
   
<a href="#u12">12</a>. void solve (const valarray&lt;T&gt;&amp; <i>v</i>, valarray&lt;T&gt;&amp; <i>s</i>) const;
<a href="#u13">13</a>. void solve (const matrix&lt;T&gt;&amp; <i>v</i>, matrix&lt;T&gt;&amp; <i>s</i>) const;

</code></pre>

<p>
<ol>
<li><a name="u1"></a>Performs LU decomposition on a square matrix, i.e., the matrix A is decomposed as,
<center><h4>
A = L . U
</h4></center>
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 <i>ri</i> for performing the back substitution later. The method throws <i>invalid_argument</i> exception for non-square matrix if range checking is enabled. It can also throw <i>runtime_error</i> exception if the matrix is found singular during decomposition. Returns the determinant of the matrix.
</li><br><br>

<li><a name="u2"></a>Performs forward and back substitution on a LU decomposed matrix to find out the solution vector for a linear set of equations. Here, <i>v</i> is the right hand side input vector and <i>ri</i> is the row index as returned by <i>lud</i> method. The solution vector will be returned in the vector <i>s</i>.
</li><br><br>

<li><a name="u3"></a>The <i>lumpove</i> 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, <i>ludm</i> is the LU decomposition of the original matrix, <i>v</i> is the right hand side vector and <i>ri</i> is the row index. The improved solution will be returned in the vector <i>s</i>.
</li><br><br>

<li><a name="u4"></a>Performs Singular Value decomposition on a matrix, i.e., any M x N matrix A, where M >= N, is decomposed as,
<center><h4>
A = U . W . Z<small><sup><i>T</i></sup></small>
</h4></center>
Where <b>U</b> is an M x N column-orthogonal matrix, <b>W</b> is a diagonal matrix, and <b>Z</b> is an N x N orthogonal matrix. After successful decomposition, the original matrix A is replaced by <b>U</b>, the diagonal matrix is returned in the vector <i>w</i>, and the orthogonal matrix in <i>z</i>. This method may throw exception <i>runtime_error</i> if there is no convergence after 30 iterations.</li><br><br>

<li><a name="u5"></a>The <b>svbksb</b> method performs back substitution on a SV decomposed matrix to find out the solution vector for a linear set of equations. Here the matrix <i>z</i> and vector <i>w</i> are as returned by the <b>svd</b> method, <i>v</i> is the right hand side vector, and <i>s</i> is the solution vector to be returned by this method.
</li><br><br>

<li><a name="u6"></a>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.,
<center><h4>
A = Q . R
</h4></center>
After successful decomposition, the original matrix A is replaced by the orthogonal matrix <b>Q</b>, and the upper triangular matrix <i>R</i> is returned in <i>r</i>.
</li><br><br>

<li><a name="u7"></a>Finds the solution vector for a QR decomposed matrix. Here <i>r</i> is the upper triangular matrix returned by the <b>qrd</b> method, <i>v</i> is the right hand side vector, and <i>s</i> is the reference to a valarray class object to receive the solution vector.
</li><br><br>

<li><a name="u8"></a>The Cholesky decomposition method <b>chold</b> decomposes a symmetric, positive definite matrix A, into a lower triangular matrix L so that
<center><h4>
A = L . L<small><sup><i>T</i></sup></small>
</h4></center>
It will throw <i>runtime_error</i> exception if the matrix is not symmetric and positive definite.
</li><br><br>

<li><a name="u9"></a>The <b>cholbksb</b> method performs back substitution on a Cholesky decomposed matrix to find out the solution vector for a set of linear equations. Here <i>v</i> is the right hand side vector, and <i>s</i> is the reference to <i>valarray</i> object to receive the solution vector.</li><br><br>

<li><a name="u10"></a>Inverts the matrix. The matrix is inverted in-place using minimum memory, i.e., the original matrix is replaced by its inverse. </li><br><br>

<li><a name="u11"></a>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 <b>inv</b> and is also slightly slower. </li><br><br>

<li><a name="u12"></a>Solves a set of linear equations using LU decomposition method. Here <i>v</i> is the right hand side vector, and <i>s</i> is the reference to <i>valarray</i> object to receive the solution vector.</li><br><br>

<li><a name="u13"></a>Solves a set of linear equations using LU decomposition method. The matrix <i>v</i> can 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 <i>s</i>.</li><br><br>
</ol>
</p>

<h5>Examples</h5>

<pre><code>typedef matrix&lt;double&gt; Matrix;
typedef valarray&lt;double&gt; Vector;

Matrix A(5,5), Z(5,5);
Vector V(5), S(5), W(5);
valarray&lt;size_t&gt; ri;

cin >> A >> V;                  // Reads the matrix and vector from stdin
Matrix B = A;

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);

</code></pre>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -