function animate

load pend_length
load theta

% Coordenadas cartesianas da extremidade de cada elo
x1=L1*cos(theta(2,:));
y1=L1*sin(theta(2,:));
x2=x1+L2*cos(theta(2,:)+theta(3,:));
y2=y1+L2*sin(theta(2,:)+theta(3,:));

for i=1:length(theta)
    % Desenho dos elos
    plot([0,x1(i)], [0,y1(i)], 'r', ...
         [x1(i),x2(i)], [y1(i),y2(i)], 'b', ...
         0,0,'ro', x1(i),y1(i),'bo', x2(i),y2(i),'bs', 'linewidth',3);
    axis('equal'), axis(1.1*(L1+L2)*[-1 1 -1 1]);

    drawnow;

    % Apresentaçao do instante de simulaçao
    t=theta(1,i);
    if (t*10-floor(t*10)==0.0)
        fprintf('time=%g \r',theta(1,i));
    end
end