# When does GMRES method compute norm of residual incorrectly?

I'm trying to diagnose what I assume is a bug in a code that uses the GMRES method to solve a system of linear equations. At each GMRES iteration the norm of the residual is printed. When GMRES converges the norm of the residual is computed manually. Usually these two norms agree with each other, but now they do not. The actual norm of the residual is many orders of magnitude larger than the one computed iteratively with GMRES.

The third edition of Matrix Computations by Golub and Van Loan (algorithm 10.4.4) says how the GMRES algorithm computes this norm, $h_{k+1,k}$, iteratively. It also says it is easy to verify that $$\left\Vert b-Ax_{k}\right\Vert =h_{k+1,k}$$

From past experience I know that these two norms can disagree when GMRES is attempting to solve a nonlinear system (I.e. the matrix $A$ depends on $x$). Since GMRES can be implemented as a matrix-free algorithm, this mistake is easier to make than one may expect. I've checked my code for this type of mistake and cannot find any.

What other circumstances can cause these two norms, which agree analytically, to disagree numerically?

• What's the condition number of the matrix?
– user3417
Jun 6, 2018 at 20:16
• @Metahominid I think the problem with my code was the matrix was ill-conditioned. I was enforcing a physical boundary condition that contradicts the other physics in the PDE I'm solving. Once I changed the boundary condition the two norms agreed, and I was able to get a sensible solution. Jun 6, 2018 at 22:03
• that sounds reasonable
– user3417
Jun 6, 2018 at 22:08