![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Program to compute the QR decomposition of a given matrix. More...
#include <array>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include "./qr_decompose.h"
Go to the source code of this file.
Functions | |
int | main (void) |
template<typename T> | |
void | qr_decompose (const std::valarray< std::valarray< T > > &A, std::valarray< std::valarray< T > > *Q, std::valarray< std::valarray< T > > *R) |
template<typename T> | |
std::ostream & | operator<< (std::ostream &out, std::valarray< std::valarray< T > > const &v) |
Program to compute the QR decomposition of a given matrix.
Definition in file qr_decomposition.cpp.
int main | ( | void | ) |
main function
Definition at line 23 of file qr_decomposition.cpp.
std::ostream & qr_algorithm::operator<< | ( | std::ostream & | out, |
std::valarray< std::valarray< T > > const & | v ) |
operator to print a matrix
Definition at line 33 of file qr_decompose.h.
void qr_algorithm::qr_decompose | ( | const std::valarray< std::valarray< T > > & | A, |
std::valarray< std::valarray< T > > * | Q, | ||
std::valarray< std::valarray< T > > * | R ) |
Decompose matrix \(A\) using Gram-Schmidt process.
\begin{eqnarray*} \text{given that}\quad A &=& *\left[\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_{N-1},\right]\\ \text{where}\quad\mathbf{a}_i &=& \left[a_{0i},a_{1i},a_{2i},\ldots,a_{(M-1)i}\right]^T\quad\ldots\mbox{(column vectors)}\\ \text{then}\quad\mathbf{u}_i &=& \mathbf{a}_i *-\sum_{j=0}^{i-1}\text{proj}_{\mathbf{u}_j}\mathbf{a}_i\\ \mathbf{e}_i &=&\frac{\mathbf{u}_i}{\left|\mathbf{u}_i\right|}\\ Q &=& \begin{bmatrix}\mathbf{e}_0 & \mathbf{e}_1 & \mathbf{e}_2 & \dots & \mathbf{e}_{N-1}\end{bmatrix}\\ R &=& \begin{bmatrix}\langle\mathbf{e}_0\,,\mathbf{a}_0\rangle & \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle & \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots \\ 0 & \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle & \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\ 0 & 0 & \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\ \vdots & \vdots & \vdots & \ddots \end{bmatrix}\\ \end{eqnarray*}
A | input matrix to decompose |
Q | output decomposed matrix |
R | output decomposed matrix |
Definition at line 146 of file qr_decompose.h.