26 template <
class Matrix,
class Vector,
class Preconditioner,
class Real >
28 CG(
const Matrix &A, Vector &x,
const Vector &b,
29 const Preconditioner &M,
int &max_iter, Real &tol)
33 Vector alpha(1), beta(1), rho(1), rho_1(1);
41 if ((resid =
norm(r) / normb) <= tol) {
47 for (
int i = 1; i <= max_iter; i++) {
56 beta(0) = rho(0) / rho_1(0);
61 alpha(0) = rho(0) /
dot(p, q);
66 if ((resid =
norm(r) / normb) <= tol) {
int CG(const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int &max_iter, Real &tol)
Iterative template routine – CG.
Iterative template routines.
A::value_type dot(const A &a, const B &b)
Dot product of array or expression.
A::value_type norm(const A &a)
Euklidean norm of array or expression.