Closed Form Solution
The following is the MATLAB code for closed form solution
of mass-spring-damper system.
clear all;
m = 2; % mass of the system in meter
k = 5000; % stiffness of the spring (N/m)
c = You need to set this value; % damping coefficient (N*s/m)
wn = sqrt(k/m); % natural frequency (rad/sec)
zeta = c/(2*wn*m); % viscous damping factor
wd = YOU ADD OMEGA_DAMPED HERE !!;
% wd is the damped natural frequency
t_final = 3; % calculation time
n = 5000; % number of data points
At the beginning of the program, we need to write some constant inputs.
n is the number of the data points.
x_0 = 1; % initial displacement for homogeenous
% solution
xdot_0 = 0; % initial velocity for homogeenous solution
Then, initial conditions are followed.
X_0 = CHANGE this line for amplitude ;
phi = CHANGE this line for phase angle ;
% X_0 is the amplitude of response and
% phi is the phase angle of the response
% Remember that this is about complimentary (homogeneous) solution
% therefore, only thing you have to include is initial conditions
Calculate the amplitude and the phase angle with given
initial conditions.
t = 0:t_final/n:t_final;
x = X_0*exp(-zeta*wn*t).*cos(wd*t+phi); % displacement x(t)
xdot = X_0*exp(-zeta*wn*t).*(-zeta*wn*cos(wd*t+phi)-wd*sin(wd*t+phi));
% velocity xdot(t)
And we can determine the displacement x(t) and velocity
xdot(t).
Click here for the entire MATLAB
source code for closed form solution.