MAT 275 Laboratory 5
The MassSpring System
In this laboratory we will examine harmonic oscillation. We will model the motion of a massspring system with diﬀerential equations.
Our objectives are as follows:
 Determine the eﬀect of parameters on the solutions of diﬀerential equations.
 Determine the behavior of the massspring system from the graph of the solution.
 Determine the eﬀect of the parameters on the behavior of the massspring.
The primary MATLAB command used is the ode45 function.
MassSpring System without Damping
The motion of a mass suspended to a vertical spring can be described as follows. When the spring is not loaded it has length !_{0} (situation (a)). When a mass m is attached to its lower end it has length ! (situation (b)). From the first principle of mechanics we then obtain
mg 
+−k(! − !_{0}) 
= 0. 
(L5.1) 

!"#$ 
! 

"# 

$ 







downward weight force 
upward tension force 


The term g measures the gravitational acceleration (g " 9.8m/s^{2} " 32f t/s^{2}). The quantity k is a spring constant measuring its stiﬀness. We now pull downwards on the mass by an amount y and let the mass go (situation (c)). We expect the mass to oscillate around the position y = 0. The second principle of mechanics yields
mg + −k(! + y − !_{0}) 
= 

!"#$ 
! 

"# 

$ 





weight 
upward tension force 
using (L5.1). This ODE is secondorder.

d^{2} 
(! + y) 

d^{2}y 



m 







, i.e., 
m 

+ ky = 0 
(L5.2) 


dt^{2} 


dt^{2} 

! 


"# 


$ 








of 





acceleration 

mass 




!_{0} 
k 



! 




y 


m 





γ 
(a) 
(b) 
(c) 
(d) 
Equation (L5.2) is rewritten
d^{2}y 
+ ω_{0}^{2}y = 0 
(L5.3) 

dt^{2} 



#c2011 Stefania Tracogna, SoMSS, ASU
MATLAB sessions: Laboratory 5
where ω_{0}^{2} = k/m. Equation (L5.3) models simple harmonic motion. A numerical solution with initial conditions y(0) = 0.1 meter and y^{!} (0) = 0 (i.e., the mass is initially stretched downward 10cms and released, see setting (c) in figure) is obtained by first reducing the ODE to firstorder ODEs (see Laboratory 4).
Let v = y^{!} . Then v^{!} = y^{!!} = −ω_{0}^{2}y = −4y. Also v(0) = y^{!} (0) = 0. The following MATLAB program implements the problem (with ω_{0} = 2).
function LAB05ex1
m = 1; % mass [kg]
k = 4; % spring constant [N/m]
omega0 = sqrt(k/m);
y0 = 0.1; v0 = 0; % initial conditions
[t,Y] = ode45(@f,[0,10],[y0,v0],[],omega0); % solve for 0<t<10
y = Y(:,1); v = Y(:,2); % retrieve y, v from Y
figure(1); plot(t,y,’b+’,t,v,’ro’); % time series for y and v
grid on;
%
function dYdt = f(t,Y,omega0) y = Y(1); v = Y(2);
dYdt = [ v ; omega0^2*y ];
Note that the parameter ω_{0} was passed as an argument to ode45 rather than set to its value ω_{0} = 2 directly in the function f. The advantage is that its value can easily be changed in the driver part of the program rather than in the function, for example when multiple plots with diﬀerent values of ω_{0} need to be compared in a single MATLAB figure window.
0.2 










0.15 










0.1 










0.05 










0 










−0.05 










−0.1 










−0.15 










−0.2 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
0 
Figure L5a: Harmonic motion
 From the graph in Fig. L5a answer the following questions.
 Which curve represents y = y(t)? How do you know?
 What is the period of the motion? Answer this question first graphically (by reading the period from the graph) and then analytically (by finding the period using ω_{0}).
 We say that the mass comes to rest if, after a certain time, the position of the mass remains within an arbitrary small distance from the equilibrium position. Will the mass ever come to rest? Why?
#c2011 Stefania Tracogna, SoMSS, ASU
 What is the amplitude of the oscillations for y?
 What is the maximum velocity (in magnitude) attained by the mass, and when is it attained? Make sure you give all the tvalues at which the velocity is maximum and the corresponding
maximum value. The tvalues can be determined by magnifying the MATLAB figure using the magnify button , and by using the periodicity of the velocity function.
(f ) How does the size of the mass m and the stiﬀness k of the spring aﬀect the motion? Support your answer first with a theoretical analysis on how ω_{0} – and therefore the period of the oscillation – is related to m and k, and then graphically by running LAB05ex1.m first with m = 5 and k = 4 and then with m = 1 and k = 16. Include the corresponding graphs.
 The energy of the massspring system is given by the sum of the potential energy and kinetic energy. In absence of damping, the energy is conserved.
 Plot the quantity E = ^{1}_{2} mv^{2} + ^{1}_{2} ky^{2} as a function of time. What do you observe? (pay close attention to the yaxis scale and, if necessary, use ylim to get a better graph). Does the graph confirm the fact that the energy is conserved?
 Show analytically that ^{dE}_{dt} = 0.(Note that this proves that the energy is constant).
 Plot v vs y (phase plot). Does the curve ever get close to the origin? Why or why not? What does that mean for the massspring system?
MassSpring System with Damping
When the movement of the mass is damped due to viscous eﬀects (e.g., the mass moves in a cylinder containing oil, situation (d)), an additional term proportional to the velocity must be added. The resulting equation becomes



d^{2}y 

dy 

d^{2}y 

dy 




m 

+ c 

+ ky = 0 or 


+ 2p 

+ ω_{0}^{2}y = 0 
(L5.4) 
dt^{2} 


dt^{2} 






dt 


dt 


by setting p = 
c 
. The program LAB05ex1 is updated by modifying the function f: 






2m 











function LAB05ex1a 











m = 1; 






% mass [kg] 


k = 4; 






% spring constant [N/m] 


c = 1; 




% friction coefficient [Ns/m] 


omega0 = sqrt(k/m); p = c/(2*m); 







y0 = 0.1; v0 = 0; 






% initial conditions 


[t,Y] = ode45(@f,[0,10],[y0,v0],[],omega0,p); % solve for 0<t<10 


y = Y(:,1); v = Y(:,2); 




% retrieve y, v from Y 


figure(1); plot(t,y,’b+’,t,v,’ro’); 


% time series for y and v 


grid on; 











% 





function dYdt = f(t,Y,omega0,p) 







y = Y(1); v = Y(2); 











dYdt = [ v ; ?? ]; 






% fillin dv/dt 

 Fill in LAB05ex1a.m to reproduce Fig. L5b and then answer the following questions.
 For what minimal time t_{1} will the massspring system satisfy y(t) < 0.01 for all t > t_{1}? You can answer the question either by magnifying the MATLAB figure using the magnify button (include a graph that confirms your answer), or use the following MATLAB commands (explain):
#c2011 Stefania Tracogna, SoMSS, ASU
MATLAB sessions: Laboratory 5
0.2 








y(t) 





















v(t)=y’(t) 

0.15 










0.1 










0.05 










0 










−0.05 










−0.1 










−0.15 










−0.2 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
0 
Figure L5b: Damped harmonic motion
for i=1:length(y) m(i)=max(abs(y(i:end)));
end
i = find(m<0.01); i = i(1);
disp([’y<0.01 for t>t1 with ’ num2str(t(i1)) ’<t1<’ num2str(t(i))])
 What is the maximum (in magnitude) velocity attained by the mass, and when is it attained? Answer by using the magnify button and include the corresponding picture.
 How does the size of c aﬀect the motion? To support your answer, run the file LAB05ex1.m for c = 2, c = 4, c = 6 and c = 8. Include the corresponding graphs with a title indicating the value of c used.
 Determine analytically the smallest (critical) value of c such that no oscillation appears in the solution.
4. (a) Plot the quantity E = 
1 _{mv}2 
+ ^{1} ky^{2} 
as a function of time. What do you observe? Is the 

2 
2 

energy conserved in this case?
 Show analytically that ^{dE}_{dt} < 0 for c > 0 while ^{dE}_{dt} > 0 for c < 0.
 Plot v vs y (phase plot). Comment on the behavior of the curve in the context of the motion of the spring. Does the graph ever get close to the origin? Why or why not?
#c2011 Stefania Tracogna, SoMSS, ASU
Wordpower1
 Ratings 12
 Grade: A
 Questions 0
 Solutions 1104
 Blog 0
 Earned: $4956.40