% EG2p8Residual.m Example 2.8 Heath
% Small residual doesn't imply a small rel. error if A is ill-conditioned.
% The exact solution is x = [1; -1].
% Solution x1 has a very large relative error and yet has a small residual.
% Solution x2 is a reasonably accurate solution and yet its residual is
% much large than that of x1.
% K. Ming Leung, 02/12/04

clear; format short e;
A = [0.913 0.659; 0.457 0.330];
b = [0.254; 0.127];
x1 = [-0.0827; 0.5];
x2 = [0.999; -1.01];

% residual 1:
r1 = b - A*x1, r1_norm = norm(r1,1),
r2 = b - A*x2, r2_norm = norm(r2,1),

% A is ill-conditioned, it has a large condition number:
conditionA = cond(A),
