Newer
Older
The purpose of this project is to implement a family of Power Methods as well as the QR method to **calculate the real-valued eigenvalues of square real-valued dense and sparse matrices**.
A family of Power Method classes are available:
- *Power Method*
- *Inverse Power Method*
- *Power Method with Shift*
- *Inverse Power Method with Shift*
The above classes have to ability to calculate the dominating eigenvalue (method dependent) of a matrix.
In addition, these classes can calculate all the eigenvalues of a matrix using deflation. However, **these methods can be numerically unstable** (especially for the Inverse Power Methods) and are not always recommended.
Instead, the *QRMethod* class should be used to calculate all the eigenvalues of a matrix.
> [Warning]
> Currently, only dense and sparse matrices of type double from the *eigen* library are supported. However, allowing different scalar typed matrices **in the future** should be simple as most methods are templated
## Compilation
In order to compile it you should first install *googletest* and *eigen*
Then, building is done as usual, e.g. with CLion/VSCode or in the terminal:
```
mkdir build
cd build
cmake ..
make
```
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
## Tests
We have provided some simple tests for our methods:
- Diagonal 5x5
- Triangular 5x5
- Dense 5x5
- Triangular 10x10
- Diagonal sparse 5x5
- Triangular sparse 10x10
- Sparse 10x10
- Exceeded Maximum allowed iterations
In order to run these tests, use CLion/VSCode or run the following lines in the command line:
enter code here
## Documentation
In order to create the documentation, make sure to have *doxygen* installed, and run the following lines in the terminal:
cd documentation
doxygen
## Examples
Given a dense (`Eigen::MatrixXd`A) or sparse (`Eigen::SparseMatrix<double> A` ) matrix A
### PowerMethod
PowerMethod power;
double largest_eigenvalue = power.FindLargestEigenvalue(A);
Eigen::VectorXd all_eigenvalues= power.FindEigenvalues(A);
The user can also select the tolerance and maximum iterations allowed for the power methods:
PowerMethod new_power(1e-5, 10);
### InversePowerMethod
InversePowerMethod inversepower;
double smallest_eigenvalue = inversepower.FindSmallestEigenvalue(A);
Eigen::VectorXd all_eigenvalues= inversepower.FindEigenvalues(A); //Not Recommended
### PowerMethodShift & InversePowerMethodShift
PowerMethodShift powershift(0.5); //Shift of 0.5
Eigen::VectorXd all_evals = powershift.FindEigenvalues(A);
double shifted_eval = inversepower.FindShiftedEigenvalue(A);
InversePowerMethodShift inversepowershift;
double inverse_shifted_eval = inversepowershift.FindShiftedEigenvalue(A);
Eigen::VectorXd all_evals = inversepowershift.FindEigenvalues(A); //Not Recommended
In addition, the shift can be adjusted to find different eigenvalues:
powershift.SetShift(1.5);
double new_shifted_eval = inversepower.FindShiftedEigenvalue(A);
### QRMethod
QRMethod qr;
Eigen::VectorXd all_evals = qr.FindEigenvalues(A);