Vecrot

%VECROT Animation program which shows a rotating vector     –  1
%       defined as a complex number                         –  2
%       This program uses facilities avalable in MATLAB 3.5
%       See Section 4.10 in book.

f = 50;         % frequency, Hz                             –  3
omega = 2*pi*f; % angular frequency, rad/s                  –  4
tmax = 1/50;    % time for a complete rotation, s           –  5
time   = [ ];                                             % –  6
motion = [ ];                                             % –  7
axis(‘square’)                                    % –  8
axis([-1 1 -1 1])                                 % –  9
for t = 0: tmax/36: tmax                                  % – 10
z = exp(i*omega*t);    % complex number description – 11
x = real(z);           % cartesian projections      – 12
y = imag(z);                                      % – 13
time   = [ time t ];                              % – 14
motion = [ motion y ];                            % – 15
plot([0, x], [0, y])                              % – 16
pause(1.0)                                        % – 17
end                                                       % – 18