%animation of sin and cosine
clc
clear all
n = input('Enter number of sine and cosine cycles: ');
y = input('Enter number of hits: ');
choice = input('Trace locus yes or No: ','s');
choice = lower(choice);
x = n*360;
h = 1;
clc
switch choice
case 'yes'
k = 0:x;
figure('menubar','no','color','k','numbertitle','off','resize','off','name','TRACE SIN AND COS')
plot(k,sind(k),k,cosd(k),'linewidth',2)
h1 = line(k,sind(k),'marker','o','markersize',14,'markerfacecolor','w');
h2 = line(k,cosd(k),'marker','o','markersize',14,'markerfacecolor','y');
while h <= y
for k = 0:x
set(h1,'xdata',k,'ydata',sind(k))
set(h2,'xdata',k,'ydata',cosd(k))
axis([0 x -1 1])
axis square off
drawnow
end
for k = x:-1:0
set(h1,'xdata',k,'ydata',sind(k))
set(h2,'xdata',k,'ydata',cosd(k))
axis([0 x -1 1])
axis square off
drawnow
end
h = h+1;
end
case 'no'
figure('menubar','no','color','k','numbertitle','off','resize','off','name','SIN AND COS')
while h <= y
for k = 0:x
plot(k,sind(k),'o','markersize',14,'markerfacecolor','w')
hold on
plot(k,cosd(k),'o','markersize',14,'markerfacecolor','y');
hold off
axis([0 x -1 1])
axis square off
drawnow
end
for k = x:-1:0
plot(k,sind(k),'o','markersize',14,'markerfacecolor','w')
hold on
plot(k,cosd(k),'o','markersize',14,'markerfacecolor','y');
hold off
axis([0 x -1 1])
axis square off
drawnow
end
h = h+1;
end
otherwise
disp('INVALID SELECTION SELECT EITHER YES OR NO')
return
end
clear all