function animate_pendulum(times,sols,L,K)
[m,n] = size(sols);
if (n==2)
    xa = -K*sols(:,1);
else
    xa = sols(:,3);
end
xp = xa + L*sin(sols(:,1));
yp =             L*cos(sols(:,1));
maxv = max(max(max(xp),max(xa)),max(yp));
minv = min(min(xp),min(yp));
if (minv>0) minv = -0.1; end
if (maxv<0) maxv = 0.1; end
dx = 0.505*(maxv-minv);
xcen = 0.5*(max(xp)+min(min(xp),0));
ycen = 0.5*(max(yp)+min(min(yp),0));
figure;
for i = 1:length(times)
    clf
    ylim([ycen-dx ycen+dx]);
    xlim([xcen-dx xcen+dx]);
    axis square;
    hold on;
    plot(xp(i),yp(i),'ro','MarkerSize',11,'MarkerFaceColor',[1,0,0]);
    plot([xa(i),xp(i)],[0,yp(i)],'LineWidth',2)
    plot([0,xa(i)],[0,0],'LineWidth',2,'Color',[0,0,0]);
    plot([xa(i)/4,3*xa(i)/4],[0,0],'LineWidth',11,'Color',[0,0,0]);
    pause(0.05)
end

end