% convergence of 4th order finite differences
%
  nvec = 2.^(3:12);
  for N=nvec
     h = 2*pi / N;
     x = -pi + (1:N)'*h;
     u = exp(sin(x));
     uprime = cos(x) .* u;
%
     e = ones(N,1);
     D =   sparse(1:N, [2:N 1], 2*e/3, N, N) ...
         - sparse(1:N, [3:N 1 2], e/12, N, N);
     D = (D - D') / h;
%
     err = norm(D*u-uprime, inf);
     loglog(N, err, '.', 'markersize', 14);
     hold on;
  end
%
  grid on, xlabel 'N', ylabel 'error';
  title('Convergence of 4th order finite differences');
  semilogy(nvec, nvec.^(-4), '--');
