% MITES08: Underdamped Oscillations [underdampedSHM.m]
% June 28, 08 [Sat.]
% Plots underdamped simple harmonic motion.

clear;

% Case 1: Underdamped oscillation.

% ***** USER: Change the parameters and explore *****
% Caution: Make sure "omega0" > "gamma" for underdamped case!!
C = 5;  % Initial amplitude.
phi = pi/2; % Phase shift.
gamma = 1;  % "Effective" strength of damping.
omega0 = 30; % Natural angular frequency.
omegaenne = sqrt(omega0^2 - gamma^2);  % omega tilde (aka. omegaenne)

% ***** Change the following parameter for plotting **** 
n = 30;  % For how many periods would you like to plot the motion of particle?


% After solving EOM for underdamped oscillation (Pg.35 of lecture notes)
% we obtain "underdampedSHO" being x(t) = position of particle
t = linspace(0,n*2*pi/omegaenne,1000); % Time: from 0s to 2*pi/omegaenne, in 1000 increments.
underdampedSHO = C*exp(-gamma*t).*cos(omegaenne*t - phi); 

% Plot underdamped case:
plot(t, underdampedSHO, '-r');
hold on
plot(t, C*exp(-gamma*t), '--b');
plot(t, -C*exp(-gamma*t), '--b');
xlabel('time');
ylabel('Position of underdamped SHO');
title('Motion of particle in underdamped simple harmonic oscillator (SHO)');
legend('Actual position','Cexp(-\gamma t): Amplitude decay',1);
hold off



