n=5;          % need large size
disp(['dim n is: ',num2str(n)]);
disp('First: generate random B,b and solve Bx=b and show (small) error');
B=randn(n);bb=randn(n,1);xb=B\bb;
disp(['norm(B*xb-bb)   ',num2str(norm(B*xb-bb))]);
%%%%%%%%%%%%%%%%%%%%%%
disp('hit any key to continue')
keyboard
disp(' ');
disp(' ')
disp('Now generate special A and random b and show LARGE error');
A=-ones(n);
A=tril(A);
A(1:n+1:end)=ones(n,1);
A=A(:,1:n-1);
A=[A [ones(n-1,1);-1]];
A(n,n)=1;
b=randn(n,1);
x=A\b;
disp(['norm(A*x-b)   ',num2str(norm(A*x-b))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%%%%%%%%%%%%%%%%%%%%%%
disp('hit any key to continue')
keyboard
disp(' ');
disp(' ')
disp('Now solve perturbed problem and show improved error');
pert=randn(n);pertmax=max(max(abs(pert)));
Ap=A+pert/(pertmax*1e9);
xp=Ap\b;
disp(['perturbed problem norm(Ap*xp-b)   ',num2str(norm(Ap*xp-b))]);
disp(['perturbed solution in original problem norm(A*xp-b)   ',num2str(norm(A*xp-b))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('hit any key to continue')
keyboard
disp(' ');
disp(' ')
disp('now loop with increasing dimension')
for n=10:10:200,
disp(' ');
disp(' ');
disp(' ');
disp(['dim n is: ',num2str(n)]);
disp('Now generate special A and random b and show LARGE error');
A=-ones(n);
A=tril(A);
A(1:n+1:end)=ones(n,1);
A=A(:,1:n-1);
A=[A [ones(n-1,1);-1]];
A(n,n)=1;
b=randn(n,1);
x=A\b;
disp(['norm(A*x-b)   ',num2str(norm(A*x-b))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%%%%%%%%%%%%%%%%%%%%%%
disp('hit any key to continue')
keyboard
disp(' ')
disp('Now solve perturbed problem and show improved error');
pert=randn(n);pertmax=max(max(abs(pert)));
Ap=A+pert/(pertmax*1e9);
xp=Ap\b;
disp(['perturbed problem norm(Ap*xp-b)   ',num2str(norm(Ap*xp-b))]);
disp(['perturbed solution in original problem norm(A*xp-b)   ',num2str(norm(A*xp-b))]);
end
