|
EllAlgo 1.6.13
|
Conjugate gradient method for solving linear systems. More...
#include <cmath>#include <stdexcept>#include <string>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| class | Vector0 |
| A simple vector class for conjugate gradient calculations. More... | |
| class | Matrix0 |
| A simple matrix class for conjugate gradient calculations. More... | |
Functions | |
| Vector0 | operator+ (Vector0 lhs, const Vector0 &rhs) |
| Element-wise vector addition. | |
| Vector0 | operator- (Vector0 lhs, const Vector0 &rhs) |
| Element-wise vector subtraction. | |
| Vector0 | operator* (Vector0 v, double scalar) |
| Scalar-vector multiplication (vector * scalar) | |
| Vector0 | operator* (double scalar, Vector0 v) |
| Scalar-vector multiplication (scalar * vector) | |
| template<typename Matrix0 , typename Vector0 > | |
| Vector0 | conjugate_gradient (const Matrix0 &A, const Vector0 &b, const Vector0 *x0=nullptr, double tol=1e-5, int max_iter=1000) |
| Solve Ax = b using the conjugate gradient method. | |
Conjugate gradient method for solving linear systems.
This header provides classes and functions for solving linear systems using the conjugate gradient method. It includes a simple Vector and Matrix class for demonstration purposes.
|
inline |
Solve Ax = b using the conjugate gradient method.
The Conjugate Gradient method iteratively solves \(Ax = b\) where \(A\) is symmetric positive-definite.
The update at each iteration \(k\) is:
\[ \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 \]
| Matrix0 | The matrix type, which must support matrix-vector multiplication. |
| Vector0 | The vector type, which must support vector operations. |
| A | The matrix A in the linear system Ax = b. |
| b | The right-hand side vector b in the linear system Ax = b. |
| x0 | An optional initial guess for the solution vector. |
| 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. |
Scalar-vector multiplication (scalar * vector)
| [in] | scalar | The scalar value |
| [in] | v | The vector to multiply |
Scalar-vector multiplication (vector * scalar)
| [in] | v | The vector to multiply |
| [in] | scalar | The scalar value |
Element-wise vector addition.
| [in] | lhs | Left-hand side vector |
| [in] | rhs | Right-hand side vector |