%
% Explicit Euler for pendulum
%
% u'' + sin(u) = 0  (u'=v)
%
dt=0.05; tmax = 50;
n=tmax/dt;
u = zeros(1,n+1); u(1)=1;
v = zeros(1,n+1); v(1)=1;
for j=1:n
    u(j+1) = u(j)+dt*v(j);
    v(j+1) = v(j)-dt*sin(u(j));
end
t=[0:dt:tmax];
figure(1)
plot(u,v); axis('square'); ylabel('d\theta/dt');xlabel('\theta');
figure(2)
plot(t,u); xlabel('t'); ylabel('theta');

    
    