|
EllAlgo 1.6.13
|
Alternative conjugate gradient method for solving linear systems. More...
#include <cmath>#include <stdexcept>#include <string>Go to the source code of this file.
Functions | |
| template<typename Matrix , typename Vector > | |
| Vector | conjugate_gradient2 (const Matrix &A, const Vector &b, Vector &x_vector, double tol=1e-5, int max_iter=1000) |
Alternative conjugate gradient method for solving linear systems.
This header provides an alternative implementation of the conjugate gradient method using operator overloading instead of method calls.
| Vector conjugate_gradient2 | ( | const Matrix & | A, |
| const Vector & | b, | ||
| Vector & | x_vector, | ||
| double | tol = 1e-5, |
||
| int | max_iter = 1000 |
||
| ) |
Solves a system of linear equations \(Ax = b\) using the Conjugate Gradient method.
The update at each iteration \(k\):
\[ \alpha_k = \frac{r_k^T r_k}{d_k^T A d_k}, \qquad x_{k+1} = x_k + \alpha_k d_k \]
\[ r_{k+1} = r_k - \alpha_k A d_k, \qquad \beta_k = \frac{r_{k+1}^T r_{k+1}}{r_k^T r_k}, \qquad d_{k+1} = r_{k+1} + \beta_k d_k \]
| Matrix | The type of the matrix A. |
| Vector | The type of the vectors b and x_vector. |
| A | The matrix A in the system of linear equations Ax = b. |
| b | The right-hand side vector b in the system of linear equations Ax = b. |
| x_vector | The initial guess for the solution vector. This vector will be updated in-place. |
| tol | The tolerance for the residual norm, used as the stopping criterion. |
| max_iter | The maximum number of iterations to perform. |
| std::runtime_error | if the Conjugate Gradient method does not converge after the maximum number of iterations. |