%
% Convergence
%
% Explicit Euler for linear pendulum
%
% u'' + u = 0  (u'=v)
%
tmax = 2*pi
nn = [10 20 40 80 160 320 640 1280 2500]
error=[];
for n=nn
    dt = tmax/n;
    u=1;
    v=1;
    for j=1:n
        un = u+dt*v;
        v = v-dt*u;
        u=un;
    end
    error = [error norm([u v]-[1 1])];
end
figure(1)
loglog(nn,error,'o-',[100 10000],[1 0.01],':'); axis('square'); xlabel('N'); ylabel('error')
    
    