No BSD License  

Highlights from
MATLAB for Engineers

from MATLAB for Engineers by Adrian Biran
Companion Software

exe10_09.m
%EXE10_09       Solves Exercise 10.9, Swinging pendulum - animation.

%PENDUL1 animation of simple pendulum

P0  = [ 0; 0; 1 ];            % hinge centre
P1  = [ 0; -3.5; 1 ];         % rod end
rod = [ P0 P1 ];
t   = pi/2: pi/60: (5/2)*pi;  % parameter of disk curve
diskx = 2.5*cos(t); disky = 2.5*sin(t);
disk = [ diskx; disky; ones(size(t)) ];
% translate disk to point -35
ndisk = trlate(0, -35)*disk;
pendul = [ rod ndisk ];
% plot reference frame
plot(pendul(1, :), pendul(2, :))
axis([ -25 25 -40 10 ]), axis('equal')
% generate 12 frames
M = moviein(12);
angle = [ 0 5 10 15 10 5 0 -5 -10 -15 -10 -5 ];
for k = 1: 12
        swinged = rtate(angle(k))*pendul;
        plot(swinged(1, :), swinged(2, :))
        axis([ -25 25 -40 10 ]), axis('equal')
        M(:, k) = getframe;
end

Contact us at files@mathworks.com