% Implicit Euler Linear Pendulum
%
% u'' + w*u = 0
%
w=1;
dt=0.05; tmax = 300;
n=tmax/dt;
B = [1 w*dt; -w*dt 1];
u = zeros(2,n+1); u(:,1)= [1; 0];
for j=1:n
    u(:,j+1) = B*u(:,j);
end
t=[0:dt:tmax];
plot(t,u(1,:),t,cos(t)); xlabel('t'); ylabel('u');