![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Compute real eigen values and eigen vectors of a symmetric matrix using QR decomposition method. More...
#include <cassert>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include "./qr_decompose.h"Go to the source code of this file.
Namespaces | |
| namespace | qr_algorithm |
| Functions to compute QR decomposition of any rectangular matrix. | |
Macros | |
| #define | LIMS 9 |
Functions | |
| void | create_matrix (std::valarray< std::valarray< double > > *A) |
| void | mat_mul (const std::valarray< std::valarray< double > > &A, const std::valarray< std::valarray< double > > &B, std::valarray< std::valarray< double > > *OUT) |
| std::valarray< double > | qr_algorithm::eigen_values (std::valarray< std::valarray< double > > *A, bool print_intermediates=false) |
| void | test1 () |
| void | test2 () |
| int | main (int argc, char **argv) |
| template<typename T> | |
| std::ostream & | operator<< (std::ostream &out, std::valarray< std::valarray< T > > const &v) |
Compute real eigen values and eigen vectors of a symmetric matrix using QR decomposition method.
Definition in file qr_eigen_values.cpp.
| #define LIMS 9 |
limit of range of matrix values
Definition at line 20 of file qr_eigen_values.cpp.
| void create_matrix | ( | std::valarray< std::valarray< double > > * | A | ) |
create a symmetric square matrix of given size with random elements. A symmetric square matrix will always have real eigen values.
| [out] | A | matrix to create (must be pre-allocated in memory) |
Definition at line 28 of file qr_eigen_values.cpp.
| int main | ( | int | argc, |
| char ** | argv ) |
main function
Definition at line 243 of file qr_eigen_values.cpp.
| void mat_mul | ( | const std::valarray< std::valarray< double > > & | A, |
| const std::valarray< std::valarray< double > > & | B, | ||
| std::valarray< std::valarray< double > > * | OUT ) |
Perform multiplication of two matrices.
| [in] | A | first matrix to multiply |
| [in] | B | second matrix to multiply |
| [out] | OUT | output matrix (must be pre-allocated) |
Definition at line 54 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.
| void test1 | ( | ) |
test function to compute eigen values of a 2x2 matrix
\[\begin{bmatrix} 5 & 7\\ 7 & 11 \end{bmatrix}\]
which are approximately, {15.56158, 0.384227}
Definition at line 177 of file qr_eigen_values.cpp.
| void test2 | ( | ) |
test function to compute eigen values of a 2x2 matrix
\[\begin{bmatrix} -4& 4& 2& 0& -3\\ 4& -4& 4& -3& -1\\ 2& 4& 4& 3& -3\\ 0& -3& 3& -1&-1\\ -3& -1& -3& -3& 0 \end{bmatrix}\]
which are approximately, {9.27648, -9.26948, 2.0181, -1.03516, -5.98994}
Definition at line 210 of file qr_eigen_values.cpp.