R H I T

advertisement
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
EXAM 4 – Matlab Programming
NAME ___________________________________________
SECTION NUMBER _______________________________
CAMPUS MAILBOX NUMBER _____________________
EMAIL ADDRESS ________________________________@rose-hulman.edu
Problem 1 _________________/60
Problem 2 _________________/20
Problem 3 _________________/20
Total _____________________/100
Exam 3
Page 1 of 4
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
Problem 1 (60 points)
A shock absorber system can be modeled as a mass, a spring and a damper as in the picture below. The mass can
only move back and forth in the x-direction. Its displaced position will be designated by x, and its velocity by v.
spring
mass
x, v
damper
x=0 starting point
An engineer has derived the following equations to describe the behavior of the system. (Assume that we are using
SI units, with kilograms, meters, and seconds.)
2.400
4.000 At time zero, an impulse loading is supplied to the system. The effect is to give the mass an instantaneous velocity
in the positive x-direction. The initial conditions may then be written as follows.
0
2.000 0
0.000
The resulting motion of the mass is an exponentially decaying sine curve. The mass will move to the right and reach
a maximum position xmax at time tmax. The mass will then move back to the left, passing through the starting point
and reach a minimum (maximum negative valued) position xmin at time tmin. Further oscillations of decreasing
amplitude will follow.
1. (40 points) Use Matlab to plot the value of displaced position x as a function of time starting at time 0 and
ending at a time of 5.
2. (20 points) The program should print out the values of xmax, tmax, xmin and txmin with statements using the
following format.
Maximum displacement of X.XXX meters occurs at time X.XXX seconds.
Minimum displacement of -X.XXX meters occurs at time X.XXX seconds.
To get full credit in Part 2, every digit reported must be correct. In other words, your program must be accurate
enough to calculate values which will correctly round to three decimal places.
Name your m-file lastname_firstname_problem1.m Instructions on posting this file to DFS are found on Page 4.
Exam 3
Page 2 of 4
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
Problem 2 (20 points)
The pressure vessel shown at right is made up of a cylinder with a radius, R, of 0.75m
and a length, L, of 2.0m with hemispherical ends each having the same radius, R, of
0.75m.
You must write a function that will calculate the volume of water in the cylinder given
the water level in the tank as input. The water level is given by the variable h measured
from the very bottom of the tank.
R
If the water level does not exceed the level of the lower hemisphere, then the volume of
water, V, is given by the expression:
L
R
3
of water
in is
the
If the water level is somewhere in the straight section in the middle,Level
then the
volume
tank is given by “h”
given by the following expression:
h
2
3
If the water level is in the upper hemisphere, then the volume is given by the following
expression:
2
3
3
Your function should have one input for water level (h) and one output for water volume (V). Name your function
lastname_firstname_problem2.m (all lower case). Upload only this function to the DFS drive, following the
instructions on Page 4.
Exam 3
Page 3 of 4
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
Problem 3 (20 points)
Suppose we want to make a contour plot of the function
sin sin for values of x from 0 to 2 and values of y from 0 to 2. The command contour will make a contour plot, in
which each colored line represents a level, or height, ‘z’ above or below the x-y plane. To use the contour
function, the values for the x-axis need to be in an x vector which has m elements, and the values for the y-axis need
to be in a separate y vector which has n elements. The array z has m rows and n columns.
Write a program to put the correct values in the vectors and the array and make a contour plot with 7 contour levels.
Please use help and doc as needed. Choose m and n (they can even be equal), so that the curves are smooth. The
plot should look similar the figure below, but smoother and with more contour lines.
contour plot of z = sin(x)*sin(y)
6
5
y values
4
3
2
1
0
0
1
2
3
x values
4
5
6
Name your code for this problem lastname_firstname_problem3.m (all lower case). When you are done, post your
m-file answer to the correct folder on DFS:
1. Double-click on “My Network Places”. If it is not on your desktop, look in your start menu.
2. Double-click on “[DFS] Root”. Not [AFS] Root.
3. Log in with your email address and password.
4. Double-click on Academic Affairs.
5. Double-click on ME.
6. Double-click on ME123.
7. Double-click on Exams.
8. Double-click on the folder with your section number.
9. Copy and paste all your m-files to this folder.
Exam 3
Page 4 of 4
Download