MATLAB Assignment

MATLAB sessions: Laboratory 5 MAT 275 Laboratory 5 The Mass-Spring System In this laboratory we will examine harmonic oscillation. We will model the motion of a mass-spring system with di erential equations. Our ob jectives are as follows:

1. Determine the e ect of parameters on the solutions of di erential equations. 2. Determine the behavior of the mass-spring system from the graph of the solution. 3. Determine the e ect of the parameters on the behavior of the mass-spring. The primary MATLAB command used is the ode45 function. Mass-Spring 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 rst principle of mechanics we then obtain mg|{z} downward weight force + k(` `0) | {z } upward tension force = 0 : (L5.1) The term gmeasures the gravitational acceleration ( g' 9:8m=s 2' 32f t=s 2). The quantity kis a spring constant measuring its sti ness. We now pull downwards on the mass by an amount yand let the mass go (situation (c)). We expect the mass to oscillate around the position y= 0. The second principle of mechanics yields mg|{z}weight + k(`+y `0) | {z } upward tension force = m d2(`+y) dt2 | {z } acceleration of mass ;i.e., md2y dt2+ky = 0 (L5.2) using (L5.1). This ODE is second-order. (a) ( b) ( c) ( d) y ` `0 m k Equation (L5.2) is rewritten d2y dt2+!20y= 0 (L5.3) c 2016 Stefania Tracogna, SoMSS, ASU 1 MATLAB sessions: Laboratory 5 where !20= k=m . Equation (L5.3) models simple harmonic motion. A numerical solution with ini- tial conditions y(0) = 0 :4meter and y0(0) = 0 (i.e., the mass is initially stretched downward 40 cms and released, see setting (c) in gure) is obtained by rst reducing the ODE to rst-order ODEs (see Laboratory 4). Let v= y0. Then v0= y00= !20y= 9y. Also v(0) = y0(0) = 0. The following MATLAB program implements the problem (with !0= 3). function LAB05ex1 m = 1; % mass [kg] k = 9; % spring constant [N/m] omega0 = sqrt(k/m); y0 = 0.4; v0 = 0; % initial conditions [t,Y] = ode45(@f,[0,10],[y0,v0],[],omega0); % solve for 0

(a) Which curve represents y= y(t)? How do you know? (b) What is the period of the motion? Answer this question rst graphically (by reading the period from the graph) and then analytically (by nding the period using !0). (c) 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? c 2016 Stefania Tracogna, SoMSS, ASU 20 1 2 3 4 5 6 7 8 9 10 -1.5-1 -0.5 0 0.5 1 1.5 MATLAB sessions: Laboratory 5 (d) What is the amplitude of the oscillations for y? (e) What is the maximum velocity ( in magnitude ) attained by the mass, and when is it attained? Make sure you give all the t-values at which the velocity is maximum and the corresponding maximum value. The t-values can be determined by magnifying the MATLAB gure 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 kof the spring a ect the motion? Support your answer rst 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 rst with m = 5 and k= 9 and then with m = 1 and k= 18. Include the corresponding graphs. 2. The energy of the mass-spring system is given by the sum of the potential energy and kinetic energy. In absence of damping, the energy is conserved.

(a) Plot the quantity E = 12mv 2+ 12ky 2as a function of time. What do you observe? (pay close attention to the y-axis scale and, if necessary, use ylim to get a better graph). Does the graph con rm the fact that the energy is conserved? (b) Show analytically that dEdt = 0.(Note that this proves that the energy is constant). (c) Plot vvs y(phase plot). Does the curve ever get close to the origin? Why or why not? What does that mean for the mass-spring system? Mass-Spring 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 md2y dt2+cdy dt +ky = 0 or d2y dt2+ 2 pdy dt +!20y= 0 (L5.4) by setting p= c2m. The program LAB05ex1 is updated by modifying the function f: function LAB05ex1a m = 1; % mass [kg] k = 9; % spring constant [N/m] c = 1; % friction coefficient [Ns/m] omega0 = sqrt(k/m); p = c/(2*m); y0 = 0.4; v0 = 0; % initial conditions [t,Y] = ode45(@f,[0,10],[y0,v0],[],omega0,p); % solve for 0 t 1? You can answer the question either by magnifying the MATLAB gure using the magnify button (include a graph that con rms your answer), or use the following MATLAB commands (explain): c 2016 Stefania Tracogna, SoMSS, ASU 3 MATLAB sessions: Laboratory 5 Figure L5b: Damped harmonic motion for i=1:length(y) m(i)=max(abs(y(i:end))); end i = find(m<0.02); i = i(1); disp(['|y|<0.02 for t>t1 with ' num2str(t(i-1)) '

Answer by using the magnify button and include the corresponding picture. (c) How does the size of ca ect the motion? To support your answer, run the le LAB05ex1.m for c= 2, c= 6 and c= 10. Include the corresponding graphs with a title indicating the value of cused. (d) Determine analytically the smallest (critical ) value of csuch that no oscillation appears in the solution. 4. (a) Plot the quantity E = 12mv 2+ 12ky 2as a function of time. What do you observe? Is the energy conserved in this case? (b) Show analytically that dEdt < 0 for c > 0 while dEdt > 0 for c < 0. (c) Plot vvs 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? c 2016 Stefania Tracogna, SoMSS, ASU 40 1 2 3 4 5 6 7 8 9 10 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 y(t) v(t)=y'(t)