mrif = 1001;
m = mrif;
a = 0;
b = pi;
h = (b-a) / (m-1);
x = linspace(a,b,m)';
A = toeplitz(sparse([1,1],[1,2],[-2/h^2,1/h^2],1,m));
A(1,1:2) = [1/h^2,0];
A(m,m-1:m) = [0,1/h^2];
f = -sin(x);
u = A\f;
urif = u;
mrange = [20,50,100,200,500];
counter = 0;
for m = mrange+1
  counter = counter+1;
  h = (b-a) / (m-1);
  x = linspace(a,b,m)';
  A = toeplitz(sparse([1,1],[1,2],[-2/h^2,1/h^2],1,m));
  A(1,1:2) = [1/h^2,0];
  A(m,m-1:m) = [0,1/h^2];
  f = -sin(x);
  u = A\f;
  errrif(counter) = norm(u-urif(1:(mrif-1)/(m-1):mrif),inf);
  err(counter) = norm(u-sin(x),inf);
end
loglog(mrange,errrif,mrange,err,'*-',mrange,mrange.^(-2))
xlabel('m')
ylabel('error in infinity norm')
legend('error w.r.t. rif.','error w.r.t. exact','order 2')