% integrate the differential equation
clear;
a=4; % length of first arm
g=9.81; % acceleration of gravity
t=0:.01:10; % times to display
q=[2 0]; % initial conditions

[t,q]=ode45( @(t,q)[q(2);-g/a*sin(q(1))], t, q );
%plot(t,q(:,1))

% display the figure
clf;
axis([-5 5 -5 5]);
axis(gca,'equal');
axis vis3d;
arm=line([0,0],[0,-a],'Marker','o');
l=line([5,-5,-5,5,5],[5,5,-5,-5,5]);
for i=1:size(t)
  arm.XData=[0,a*sin(q(i,1))];
  arm.YData=[0,-a*cos(q(i,1))];
  drawnow;
end

