% Superposition of oscillations (this cell)
t=0:0.01:2*pi*40;

A1=1; A2=1;     % amplitudes of the two oscillations
om1=1;om2=0.7;  % frequencies
a1=0; a2=0*pi/4; % phases
shift=4;         % this is a parameter for graphical output

x1=A1*cos(om1*t+a1);
x2=A2*cos(om2*t+a2);

x=x1+x2;

plot(t,x,'r','LineWidth',4)
axis ([0 max(t) -2 2+2*shift]);
hold on
plot(t,x1+shift,'k',t,x2+2*shift,'b','LineWidth',2)
hold off
%%
% Lissajous figures  (this cell)

tmax=2*pi*10
t=0:0.01:tmax;

A1=1; A2=1;      % amplitudes of x and y oscillations
om1=1;om2=1.53;  % frequencies
a1=0; a2=2*pi/4; % phases
shift=1.3;

x1=A1*cos(om1*t+a1);  % x-oscillation
x2=A2*cos(om2*t+a2);  % y-oscillation

plot(x1,x2,'r','LineWidth',4)
axis ([-1.5 1.5 -1.5 1.5]);
hold on
plot(2*(t-tmax/2)/tmax,x1/10-shift,'k',x2/10-shift,2*(t-tmax/2)/tmax,'b','LineWidth',2)
hold off
