%test of iterative refinement
%page 232, probs 3-4 of Turner
clc
clear all
close all
format long e
%try random coefficient matrix
n = 10;
A = 10*rand(n);
b = sum(A')'; %ensures solution of all 1's
[L U] = lu(A);
y = L\b;
xexact = U\y
rexact = b-A*xexact
pause
%introduce an error 
xapprox = xexact +0.001*(0.5-rand(n,1))
r = b-A*xapprox
pause
%solve for correction to x
%deltay = L\(-r);
deltay = L\(r);
delta = U\deltay
x = xapprox+delta
pause
rnew=b-A*x


    