NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Functions
ir.h File Reference

Go to the source code of this file.

Functions

template<class Matrix , class Vector , class Preconditioner , class Real >
int IR (const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int &max_iter, Real &tol)
 

Function Documentation

template<class Matrix , class Vector , class Preconditioner , class Real >
int IR ( const Matrix &  A,
Vector &  x,
const Vector &  b,
const Preconditioner &  M,
int &  max_iter,
Real &  tol 
)

Definition at line 21 of file ir.h.

23 {
24  Real resid;
25  Vector z;
26 
27  Real normb = norm(b);
28  Vector r = b - A*x;
29 
30  if (normb == 0.0)
31  normb = 1;
32 
33  if ((resid = norm(r) / normb) <= tol) {
34  tol = resid;
35  max_iter = 0;
36  return 0;
37  }
38 
39  for (int i = 1; i <= max_iter; i++) {
40  z = M.solve(r);
41  x += z;
42  r = b - A * x;
43 
44  if ((resid = norm(r) / normb) <= tol) {
45  tol = resid;
46  max_iter = i;
47  return 0;
48  }
49  }
50 
51  tol = resid;
52  return 1;
53 }
A::value_type norm(const A &a)
Euklidean norm of array or expression.
Definition: util.hxx:54

+ Here is the call graph for this function: