% Script to plot the undamped response of a single degree of freedom system
% and to calculate its properties
% Written by Dr Colin Caprani - www.colincaprani.com

k = 100;        % N/m   - stiffness
m = 10;         % kg    - mass
delta_t = 0.1;  % s     - time step
u0 = 0.025;     % m     - initial displacement
v0 = 0;         % m/s   - initial velocity

w = sqrt(k/m);              % rad/s - circular natural frequency
f = w/(2*pi);               % Hz    - natural frequency
T = 1/f;                    % s     - natural period
ro = sqrt(u0^2+(v0/w)^2);   % m - amplitude of vibration
theta = atan(v0/(u0*w));    % rad - phase angle

t = 0:delta_t:4;
u = ro*cos(w*t-theta);

plot(t,u);
xlabel('Time (s)');
ylabel('Displacement (m)');