lab9-extra¶
sixty_degree_time(Ti, Ta, c)
¶
Implement a function sixty_degree_time(Ti, Ta, c)
which expects the
model paramaters Ti
(initial temperature), Ta
(ambient
temperature) and c
the cooling rate time constant. The function
should return an estimate of the number of seconds after which the
temperature of the drink has cooled down to 60 degree Celsius. (60
degree Celsius is a temperature that is generally considered low enough
not to damage tissue).
Hints: You have at least two different possible ways of obtaining this number of
seconds for a given set of model parameters (Ti, Ta, c)
.
One is to take the model equation \(T(t) = (T_\mathrm{i} - T_\mathrm{a})\exp\left(\frac{-t}{c}\right) + T_\mathrm{a}\) and to replace \(T(t)\) with $60$ degrees, and then solve the remaining equation for \(t\) analytically.
The other is to define a helper function \(h(t) = T(t) - 60\) so that this function is zero when \(T(t)\) is 60 degrees Celsisus. Then use root finding on this function \(h(t)\), i.e. find that value of \(t\) for which \(h(t) = 0\).
You can assume that \(T(0)\) (i.e. the initial temperature
Ti
at \(t=0\)) is greater than 60 degree Celsius, and that \(T(\infty)\) (i.e. the ambient temperatureTa
for \(t \rightarrow \infty\)) is smaller than 60 degree Celsius.
To test your functions, you can put them together like this in the IPython shell or in a separate file:
ts, Ts = read2coldata("time_temp.txt")
Ti, Ta, c = extract_parameters(ts, Ts)
print(f"Model parameters are {Ti=:.2f} C, {Ta=:.2f} C, {c=:.2f} s")
waittime = sixty_degree_time(Ti, Ta, c)
print(
f"The drink reaches 60 degrees after {waittime:.2f} seconds = {waittime/60:.2f} minutes"
)
If you want to include these commands in your submission file, you need
to put it inside the if __name__ == "___main__"
statement, such as
if __name__ == "__main__":
ts, Ts = read2coldata("time_temp.txt")
Ti, Ta, c = extract_parameters(ts, Ts)
print(f"Model parameters are {Ti=:.2f} C, {Ta=:.2f} C, {c=:.2f} s")
waittime = sixty_degree_time(Ti, Ta, c)
print(
f"The drink reaches 60 degrees after {waittime:.2f} seconds = {waittime/60:.2f} minutes"
)
Written like this, the block of commands will only be executed if you execute the main file (for example by pressing F5 in Spyder), but not if the file is imported from elsewhere (which is what the testing system does).
Please include the extra tasks in your file lab9.py
and submit as Computing lab9 assignment.
Back to lab9.
End of lab9-extra.