% MassSprgDmpr2.m uses closed form analytical solution of response of 
% a linear mass-spring-damper system (valid only for damping ratio = 1.0)
% to plot time histories of response
% to a constant force, fa, which is suddenly applied at t=0 for input values 
% of model parameters m, k, and applied force fa.

clear variables
%	Input parameter values.
m = input('Enter the mass "m" in kilograms ');
k = input('Enter the stiffness "k" in Newtons/meter ' );
b = input('Enter the damping constant "b = sqrt(4*k*m)" in kilograms/sec ');
fa= input('Enter the magnitude "fa" of the suddenly applied force in Newtons ');
%	Input initial conditions.
yo=	input('Enter the initial displacement from equilibrium, in meters ');
vo= input('Enter the initial velocity, in meters/second ');
T = input('Enter the duration "T" of the desired time history ');
%	Construct time variable "t".
delt= T/500;
t = 0 : delt : T;
% 	Evaluate behavioral parameters. 
omeg0 = sqrt(k/m);
dely = fa/k;
%	Evaluate solution parameters.
A = yo - dely;
% 	Evaluate solution.
theta = (omeg0 .*t +1);
B = A * theta + vo .*t;
y = dely + exp(-omeg0.*t) .* (A * (omeg0 .*t +1) + vo .*t);
%	Plot time history.
plot(t,y)
title('Time History of Displacement Response')
xlabel('Time [seconds]')
ylabel('Displacement [meters]')
