R H I T

advertisement
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
EXAM 4
NAME ___________________________________________
SECTION NUMBER _______________________________
CAMPUS MAILBOX NUMBER _____________________
EMAIL ADDRESS ________________________________@rose-hulman.edu
Problem 1
/ 35
Problem 2
/ 35
Problem 3
/ 30
Total
/ 100
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
Include your name, section number, and CM number in the header section of your code. There should be
no output other than what is requested.
Problem 1 (35 pts)
Name this code lastname_firstname_problem1.m (all lower case).
We wish to use Euler’s method to find the solution to the differential equation
2
with the condition that y=1 when x=0.
(a) Write a program that plots the Euler solution to this equation. Use dx=0.1 and solve the equation
while y is bigger than 0.2.
(b) Add the exact solution to the plot. The exact solution is given by
1
1
You may use the same x values for the Euler and the exact solution.
(c) Plot the exact solution using a solid line, and the Euler solution with a ‘*’. Add a legend, title, x axis
label, and y axis label to the plot.
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
Problem 2 (35 pts)
For this problem, name your main program lastname_firstname_problem2.m and your function
lastname_firstname_function.m (all lower case).
Consider a rectangular prism (like a cereal box). If the lengths of the 3 different edges are a, b, and c,
then the volume is given by
and the surface area of the box is given by
2
(a) Write a function that takes the lengths a, b, and c as inputs and returns the volume and the surface
area.
(b) Write a main routine that prints the table of values shown below by calling the function multiple times
within for loops. The table should print to the command window.
a
b
c
volume
surface area
------------------------------------1
1
1
1.00
6.00
1
1
2
2.00
10.00
1
2
1
2.00
10.00
1
2
2
4.00
16.00
2
1
1
2.00
10.00
2
1
2
4.00
16.00
2
2
1
4.00
16.00
2
2
2
8.00
24.00
Note that a substantial portion of your grade for this part of this problem depends on the use of for loops
to create the table.
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Comp Apps I
Problem 3 (30 pts)
Name your code for this problem lastname_firstname_problem3.m (all lower case).
In this problem we will generate a matrix and then view that matrix as an image.
(a) Create a 400x400 array with entries
200
200
/1000
(b) Add the command
image(z)
to your m-file to create the image shown below (yours will be in color). Add a title and axis labels.
A Pretty Image
50
100
j
150
200
250
300
350
400
50
100
150
200
i
250
300
350
400
When you are done, post your m-files to the correct folder:
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.
Download