ODE45 solver solution : main program (Unix)
%
% Mass-Spring-Damper system
% ODE45 solver solution
% ODE45 main program
%
%
% constant inputs
%
m = 1; % mass of the system in meter
k = 50; % stiffness of the spring (N/m)
c = 20; % damping coefficient
wn = sqrt(k/m); % natural frequency (rad/sec)
zeta = c/(2*wn*m) % viscous damping factor
tspan = [0,2]; % calculation time
%
% initial conditions
%
x_0 = 1; % initial displacement
x_dot_0 = 0; % initial velocity
X_0 = [x_0,x_dot_0]; % form a vector(array) of initial conditions
%
% ODE45 solver
%
[t,y] = ode45('pmsd_sol',tspan,X_0);
x = y(:,1); % displacement x(t)
x_dot = y(:,2); % velocity x_dot(t)
%
% plotting the results
%
figure(1); clf; orient tall;
subplot(2,1,1),plot(t,x);
xlabel('Time (sec.)');
ylabel('Displacement (m)');
title('Mass-Spring-Damper system : ODE45 solver result (underdamped case)')
subplot(2,1,2),plot(t,x_dot);
xlabel('Time (sec.)');
ylabel('Velocity (m/sec.)');