TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Functions to compute QR decomposition of any rectangular matrix. More...
Functions | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &out, std::valarray< std::valarray< T > > const &v) |
template<typename T > | |
std::ostream & | operator<< (std::ostream &out, std::valarray< T > const &v) |
template<typename T > | |
double | vector_dot (const std::valarray< T > &a, const std::valarray< T > &b) |
template<typename T > | |
double | vector_mag (const std::valarray< T > &a) |
template<typename T > | |
std::valarray< T > | vector_proj (const std::valarray< T > &a, const std::valarray< T > &b) |
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) |
std::valarray< double > | eigen_values (std::valarray< std::valarray< double > > *A, bool print_intermediates=false) |
Functions to compute QR decomposition of any rectangular matrix.
std::valarray< double > qr_algorithm::eigen_values | ( | std::valarray< std::valarray< double > > * | A, |
bool | print_intermediates = false ) |
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
[in,out] | A | matrix to compute eigen values for |
[in] | print_intermediates | (optional) whether to print intermediate A, Q and R matrices (default = false ) |
Definition at line 98 of file qr_eigen_values.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.
std::ostream & qr_algorithm::operator<< | ( | std::ostream & | out, |
std::valarray< T > const & | v ) |
operator to print a vector
Definition at line 53 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.
|
inline |
Compute dot product of two vectors of equal lengths
If \(\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\) and \(\vec{b}=\left[b_0,b_1,b_1,...,b_L\right]\) then \(\vec{a}\cdot\vec{b}=\displaystyle\sum_{i=0}^L a_i\times b_i\)
Definition at line 76 of file qr_decompose.h.
|
inline |
Compute magnitude of vector.
If \(\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\) then \(\left|\vec{a}\right|=\sqrt{\displaystyle\sum_{i=0}^L a_i^2}\)
Definition at line 92 of file qr_decompose.h.
std::valarray< T > qr_algorithm::vector_proj | ( | const std::valarray< T > & | a, |
const std::valarray< T > & | b ) |
Compute projection of vector \(\vec{a}\) on \(\vec{b}\) defined as
\[\text{proj}_\vec{b}\vec{a}=\frac{\vec{a}\cdot\vec{b}}{\left|\vec{b}\right|^2}\vec{b}\]
check for division by zero using machine epsilon
Definition at line 104 of file qr_decompose.h.