CS 221 PRACTICE Lab Quiz 1 2011
Part 1: Excel Fundamentals
In manufacturing metal components, pieces are hardened by heating them
to extreme temperatures and then cooling or "quenching" them in an oil
bath. The temperature of the part is a function of the time it has
been submerged in the oil bath. The equation for T(t), the
temperature at time t, is as follows:
T(t) = (Ti - Tb)e-t/τ +
Tb
where Ti is the initial temperature of the part,
Tb is the temperature of the bath, and
τ is a time constant that accounts for properties of the oil bath,
the shape of the part, etc.
Create a spreadsheet that shows the temperature of a certain part over
time, at fixed intervals of time, according to the above equation.
Use the following values for parameters:
Ti
| =
| 800 C
|
Tb
| =
| 200 C
|
τ
| =
| 50 sec
|
Time step
| =
| 0.1 sec
|
Your spreadsheet should have the following characteristics (10 points each):
- Labeled
Cells in the upper-left corner containing the values of
Ti, Tb, τ, and
the time step.
- Columns (with headers in bold)
for Time and Temperature.
- The formulas in the Temperature column
should use absolute references to the parameter values, and not
contain the values themselves.
- Temperatures should be shown to the nearest tenth of a degree.
- Correct values in the "Temperature" column, and they change
correctly when the parameter values change (i.e., the formulas are correct).
Using different values
for the constants, this is how the spreadsheet should look:
Ti (° C):
| 400
|
Tb (° C):
| 100
|
τ (sec):
| 10
|
time step (sec):
| 0.5
|
|
|
Time
|
Temperature
|
0.0 | 400.0 |
0.5 | 385.4
| 1.0 | 371.5
| 1.5 | 358.2
| 2.0 | 345.6
| 2.5 | 333.6
| 3.0 | 322.2
|
...
|
Hint: The built-in function EXP(x) computes
ex, where e is the base of the natural
logarithm.
Part 2: MATLAB Fundamentals
Write a script to compute the length (c) of the hypoteneuse of a right
triangle, given the lengths (a and b) of its two sides.
Recall that this length satisfies the equation:
c² = a² + b²
Of course, to find the value of c given a and b,
you will need to take the square root of both sides. Recall that you
can use the built-in function sqrt() in MATLAB to compute a
square root.
Your script must have the following characteristics (worth 10 points each):
- It must start with a comment (on the first line) that says:
"% hypot - compute length of hypotenuse".
- The input() function is called to get the length of the first
side from the user; it is stored in a variable called "a". The prompt
is "Please enter the length of side a: ". The output from this
assignment command should be suppressed.
- In a similar way, input() is called to get the length of the second
side from the user; it is stored in a variable called "b". The prompt
is "Please enter the length of side b: ". The output from this
assignment command should be suppressed.
- An assigment is used to compute the length of the hypotenuse and
store it in a variable called "c". The output of this assignment
is not suppressed, so that MATLAB prints "c = " and the
value assigned.
-
If either of the input lengths is 0 or negative, print an error
message saying that inputs should be positive, instead of computing
the answer.
Here is an example of how the program should behave:
>> hypot
>> Please enter the length of side a: 3
>> Please enter the length of side b: 4
>> c =
5.0000
>>