% Linear system from -u''=x %%%%%%%%%%%%%%%%%%%%%%%%%%% clear all n=25; h=1/n; n1=n-1; v=ones(n1-1,1); A=2*eye(n1)-diag(v,1)-diag(v,-1); A=n*n*A; cd=1/rcond(A) b=zeros(n1,1); xe=b; t=b; for i=1:n1 t(i)=i*h; xe(i)=1/pi^2*sin(pi*i*h); b(i) =sin(pi*i*h); end x=A\b; eta=back_comp(A,b,x) etae=norm(A*(x-xe),inf)/norm(b,inf) delta=2*eta/rcond(A) deltae=norm(xe-x,inf)/norm(x,inf) plot(t,xe,t,x) pause % It's wrong: we compare the solution of the continuous problem to the computed solution!!! % In principle, the exact solution is not known. % Assume it is given by xe(i). b=A*xe; x=A\b; eta=back_comp(A,b,x) etae=norm(A*(x-xe),inf)/norm(b,inf) delta=2*eta/rcond(A) deltae=norm(xe-x,inf)/norm(x,inf) plot(t,xe,t,x)