function [t u] = sdof_undamped(m,k,u0,v0,duration,plotflag) % This function returns the free vibration displacement of an undamped % SDOF system with parameters: % m - mass, kg % k - stiffness, N/m % u0 - initial displacement, m % v0 - initial velocity, m/s % duration - length of time of required response % plotflag - 1 or 0: whether or not to plot the response % This function returns: % t - the time vector at which the response was found % u - the displacement vector of response % Written by Dr Colin Caprani - www.colincaprani.com Npts = 1000; % compute the response at 1000 points delta_t = duration/(Npts-1); w = sqrt(k/m); % rad/s - circular natural frequency ro = sqrt(u0^2+(v0/w)^2); % m - amplitude of vibration theta = atan(v0/(u0*w)); % rad - phase angle t = 0:delta_t:duration; u = ro*cos(w*t-theta); if(plotflag == 1) plot(t,u); xlabel('Time (s)'); ylabel('Displacement (m)'); end