function pendplot(th1, th2)
% Plot or animate a double pendulum with angles th1 and th2.

nth1 = numel(th1);
nth2 = numel(th2);
if nth1 > 1 && nth2 > 1
    for i = 1:nth1
        pendplot(th1(i), th2(i));
    end
    return
end

x1 = sin(th1);
y1 = -cos(th1);

x2 = x1 + sin(th2);
y2 = y1 - cos(th2);

cla
axis equal
axis([-2.1, 2.1, -2.1, 2.1])
grid on
line([-0.2, 0.2], [0, 0], 'LineWidth', 5, 'Color', 'b')
line([0, x1, x2], [0, y1, y2], 'LineWidth', 3, 'Color', 'k')
line([x1, x2], [y1, y2], 'LineStyle', 'none', 'Marker', '.', ...
    'MarkerSize', 32, 'Color', 'r')
pause(0.01)
