Lab 6 - Answers
Lab 6 - Answers
Lab 6 - Answers
The diagram below shows a mass connected to a spring. If there were no loss of energy,
compressing or stretching the spring would result in sustained oscillations (simple harmonic
motion). However, in reality, there is a loss of energy in the spring and the amplitude of the
oscillations will decrease over time.
Depending on the characteristics of the spring and the mass, the displacement of the mass
will look like one of the two graphs shown below. The mass could oscillate around the
equilibrium point with the amplitude of the oscillations becoming smaller and smaller
(underdamped response) or the mass could simply return directly to the equilibrium point
(over-damped response).
0.8
0.8
0.6
0.4 0.6
Displacement
Displacment
0.2
0.4
0
0.2
-0.2
-0.4
0
-0.6
-0.2
-0.8
time(sec) time (sec)
α
¿
B
2 M
ω
¿
√
K
2
¿¿
B
M− 2
4M
B
¿
2
√ K ∙ M
Recall from Lab 3, the spring constant is a measure of resistance to displacement. The force
that it takes to compress or stretch the spring is directly proportional to the displacement. In
other words, it takes twice as much force to compress or stretch the spring by 10 cm than it
would to compress of stretch the spring by 5 cm.
The damping coefficient models the energy loss in the system. The damping is proportional
to the velocity of the mass. The faster the mass moves, the higher the damping force
opposing that motion will be.
Note: If B
¿
2
, the response will be over-damped (the mass simply returns
√ K ∙ M ¿ ¿
In this lab you will write a program that will allow you to explore the effects of the spring
constant, K, the damping coefficient, B, and the mass, M, on the motion of the mass.
1. Go to the recitation folder on the Blackboard metasite and download the m-file template.
Save it in whatever you use as your current folder for MATLAB with a filename:
Lab6_YourLastName. Remember, filenames follow the exact same rules as variables in
MATLAB (start with a letter followed by any combination of letters, numbers, and
underscores and no spaces allowed!)
Answer: Done!
2. In the template, fill in your name and date where indicated. You might want to wait on
the description until you have written the program.
3. Write four input statements to prompt the user for the spring constant, K, the mass, M, the
damping coefficient, B, and the initial displacement, dint. Make sure you write good
prompts for the user which include units. For example: input(‘Enter K: ‘) is
not very informative to the user. input(‘Enter the spring constant, K,
in N/m: ‘)is a much better prompt.
Answer:
your program should inform the user that the response is over-damped. Otherwise (else),
your program should inform the user that the response is underdamped. Use an fprintf
statement to do this. Display all values using two places behind the decimal point. For
example, if the response turns out to be over-damped, your program should output the
following statement:
Answer:
if B >= 2*sqrt(K*M)
fprintf('For K = %.2f N/m, B = %.2f Ns/m and M = %.2f kg, the response
is over-damped. \n',K,B,M)
else
fprintf('The response is under-damped. \n')
end
5. Now test your program. Suppose K = 200 N/m, M = 0.5 kg, and d0 = 1 m.
Calculate the range of B that will result in an over-damped response? __B ≥ 20_______
(Nm/s)
Calculate the range of B will result in an under-damped response? ______1 < B <
19_______ (Nm/s)
Run your program for various values of B and see if it produces the correct result.
6. In the underdamped section of your program (else), add a line to compute the frequency
of the oscillations, ω, in radians per second.
7. Add another line to compute the frequency of the oscillations in Hz. (Recall: ω = 2πf).
8. Add an fprintf statement that tells the user what the frequency of oscillation is in both
radians per second and in Hz. Display the frequencies using 2 places behind the decimal
point.
9. Now test your program again using the values K = 200 N/m, M = 0.5 kg, B = 4, and d o =
1m. The frequency of oscillation should be 19.6 rad/s or 3.12 Hz.
Answer: It contains the commands from questions 6, 7 and 8.
% Conditional statements
if B >= 2*sqrt(K*M)
fprintf('For K = %.2f N/m, B = %.2f Ns/m and M = %.2f kg, the response
is over-damped. \n',K,B,M)
else
fprintf('The response is under-damped. \n')
w = sqrt((K/M) - (B^2/4*M^2)); % frequency in radians per second
f = w/(2*pi); % frequency in hertz
fprintf('The frequency of the oscillation is %.2f rad/s or %.2f Hz \
n',w,f)
end
>> Lab6_Bartolomeu
Enter the spring constant, K, in N/m: 200
Enter the mass, M, in kg: .5
Enter the damping coefficient, B, in Ns/m: 4
Enter the initial displacement of the mass, dint, in m: 1
The response is under-damped.
The frequency of the oscillation is 19.97 rad/s or 3.18 Hz.
Find an equation for the time, T_END, at which this amplitude will be: d0
e− 5
. Your
equation will depend on B and M.
Note: d 0
e
−
¿
5
0.0067
d 0
so when t = T_END, the displacement of the mass will be less
than 1% of the initial displacement and the oscillations will be pretty much damped out.
11. Add a line to your program (again in the else or underdamped section), to calculate the
time, T_END at which the oscillations are effectively damped out. Add an fprintf
statement to tell the user how long it takes for the oscillations to essentially stop. Display
this value using four places behind the decimal point.
12. Test your program again using the values K = 200 N/m, M = 0.5 kg, B = 4 and d 0 = 1m.
What should T_END be? Does your program calculate and display this value correctly?
% Conditional statements
if B >= 2*sqrt(K*M)
fprintf('For K = %.2f N/m, B = %.2f Ns/m and M = %.2f kg, the response
is over-damped. \n',K,B,M)
else
fprintf('The response is under-damped. \n')
w = sqrt((K/M) - (B^2/4*M^2)); % frequency in radians per second
f = w/(2*pi); % frequency in hertz
fprintf('The frequency of the oscillation is %.2f rad/s or %.2f Hz. \
n',w,f)
T_END = (10*M)/B; % time at which oscillations stop
fprintf('The oscillations are damped out at %.4f seconds. \n',T_END)
end
>> Lab6_Bartolomeu
Enter the spring constant, K, in N/m: 200
Enter the mass, M, in kg: .5
Enter the damping coefficient, B, in Ns/m: 4
Enter the initial displacement of the mass, dint, in m: 1
The response is under-damped.
The frequency of the oscillation is 19.97 rad/s or 3.18 Hz.
The oscillations are damped out at 1.2500 seconds.
13. In the underdamped section of your code, add some lines of code to plot the underdamped
response (time on the x-axis and displacement on the y-axis) from t = 0 to t = T_END.
Choose the increment for t based on T_END
The plot should be a solid black line – format this within your code, not with plot
tools.
Label the x and y axis within your program – not with plot tools. Include units.
Add a title as part of your program code – not with plot tools.
Answer:
% Conditional statements
if B >= 2*sqrt(K*M)
fprintf('For K = %.2f N/m, B = %.2f Ns/m and M = %.2f kg, the response
is over-damped. \n',K,B,M)
else
fprintf('The response is under-damped. \n')
w = sqrt((K/M) - (B^2/4*M^2)); % frequency in radians per second
f = w/(2*pi); % frequency in hertz
fprintf('The frequency of the oscillation is %.2f rad/s or %.2f Hz. \
n',w,f)
T_END = (10*M)/B; % time at which oscillations stop
fprintf('The oscillations are damped out at %.4f seconds. \n',T_END)
t = 0:0.005:T_END;
alpha = B/(2*M);
d = dint*exp(-alpha.*t)*cos(w.*t); % displacement of the mass in meters
plot(t,d,'k-')
xlabel('Time(s)')
ylabel('Displacement(m)')
title('Under-damped Response')
end
14. Test your program again using the values K = 200 N/m, M = 0.5 kg, B = 4, and d0 = 1 m.
Paste the plot in the space below. Also paste the output from your program that appears in
the command window.
>> Lab6_Bartolomeu
Enter the spring constant, K, in N/m: 200
Enter the mass, M, in kg: .5
Enter the damping coefficient, B, in Ns/m: 4
Enter the initial displacement of the mass, dint, in m: 1
The response is under-damped.
The frequency of the oscillation is 19.97 rad/s or 3.18 Hz.
The oscillations are damped out at 1.2500 seconds.
15. Use your program to complete the following table. Use d 0 = 1 m for all cases. You only
need to include copies of the plots for the cases highlighted in yellow in the table.
Approximate
f
K (N/m) M (kg) B (Ns/m) Type of Response ω (rad/s) end time (sec)
(Hz)
of oscillations
200 0.5 4 Under-damped 19.97 3.18 1.2500
400 0.5 4 Under-damped 28.27 4.50 1.2500
800 0.5 4 Under-damped 39.99 6.36 1.2500
800 0.5 8 Under-damped 39.95 6.36 0.6250
800 0.5 16 Under-damped 39.80 6.33 0.3125
800 0.5 32 Under-damped 39.19 6.24 0.1563
800 0.5 40 Over-damped 0 0
400 1 4 Under-damped 19.90 3.17 2.5000
400 2 4 Under-damped 13.56 2.16 5.0000
400 3 4 Under-damped 9.87 1.57 7.5000
16. Describe how increasing the spring constant affects the response.
Answer: By increasing the spring constant the response becomes oscillatory and it takes
1.25 seconds to stabilize.
17. Describe how increasing the damping coefficient affects the response.
Answer: By increasing the damping coefficient, the response becomes less oscillatory and
it decreases the settling time (end time).
Answer: By increasing the mass, the response becomes more oscillatory compared to
increasing the spring constant, in addition, the response is slower, that is, the end time
increases by a significant amount.
19. If you have not done so already, add comments to your script file to explain what your
program does.
Answer: The script file I have elaborated, computes the sinusoidal motion of a mass
suspended by a spring. The script file contains the properties of the mechanical system
that are implemented by using input statements. Furthermore, the type of response is
decided using conditional statements if and fprintf, if the response is under-damped the
script file presents the frequencies, end time and the graphic behavior of the mechanical
system.