Learn the cooling model
You have not had to know this model before starting the project. Here is everything you need.
The drink begins at \(T_0=90\)°C in a room that stays at \(A=22\)°C. Newton’s law of cooling says that the drink’s temperature changes at a rate proportional to its temperature difference from the room:
\[ \frac{dT}{dt}=-k(T-A), \]
where \(T\) is the drink temperature in °C, \(t\) is time in minutes, and \(k=0.15\) per minute. The rate \(dT/dt\) is in °C per minute. When the drink is hotter than the room, \(T-A\) is positive and the minus sign makes the rate negative. As the drink approaches room temperature, the difference—and thus the size of the cooling rate—shrinks.
We will simulate from 0 through 12 minutes. For an old temperature of \(T\), the rate is -k * (T - ambient). Both methods use that same model:
\[ \begin{aligned} \text{Euler:}\quad &r_1=-k(T_{\text{old}}-A), &T_{\text{new}}&=T_{\text{old}}+r_1\Delta t,\\ \text{RK2:}\quad &r_1=-k(T_{\text{old}}-A), &T_{\text{predict}}&=T_{\text{old}}+r_1\Delta t,\\ &&r_2&=-k(T_{\text{predict}}-A),\\ &&T_{\text{new}}&=T_{\text{old}}+\frac{r_1+r_2}{2}\Delta t. \end{aligned} \]
RK2 here is the Euler predictor-corrector version from Module 6.3. The predicted temperature is used to find the second rate; the corrected update still begins with the old temperature.
A small worked example
Suppose instead that \(T=60\)°C, \(A=20\)°C, \(k=0.1\) per minute, and \(\Delta t=1\) minute. The starting rate is \(-0.1(60-20)=-4\)°C/minute. Euler predicts \(60-4(1)=56\)°C. At that predicted temperature, the rate is \(-0.1(56-20)=-3.6\)°C/minute. RK2 averages the rates and obtains \(60+(-4-3.6)(1)/2=56.2\)°C. Use the project’s values—not these demonstration values—in your simulations.
What your report should show
1. Model and assumptions
In your own words, explain why the cooling rate slows as the drink cools. State two assumptions of this model. For example, consider what it assumes about the room or the drink’s temperature throughout the cup.
2. Check the first step by hand
Using the project’s values and a two-minute step, calculate the first Euler temperature and the first corrected RK2 temperature. Show both rate calculations for RK2. Display the first two rows of each simulation and check that they agree with your work.
3. Compare methods
Simulate both methods with \(\Delta t=2\) minutes and again with \(\Delta t=0.5\) minute. Use the same starting temperature, room temperature, cooling constant, and 12-minute endpoint in all four runs. Copying and adapting your loops is fine; a function is not required.
Make one labeled graph comparing Euler and RK2 for the two-minute run. Include the exact curve described below so readers can judge the approximations visually. Use distinct line colors or styles, axis labels with units, and a legend.
For each of the four runs, report:
- the simulated temperature at minute 12; and
- the first recorded time at which the temperature is 47°C or cooler.
The first recorded time lies on your simulation’s time grid; it is not necessarily the exact moment the drink crosses 47°C.
4. Check numerical error
For this particular cooling model, the exact temperature is
\[ T(t)=A+(T_0-A)e^{-kt}. \]
You do not need to derive this formula. In R, exp(x) computes \(e^x\). Use the formula to calculate the exact temperature at minute 12 and the absolute error of each of your four simulated temperatures at that time. Present a compact table and explain what changed when you switched methods and shortened the step.
5. Recommendation
Answer the owner’s question in a short paragraph. Which waiting time would you recommend based on your simulations? Explain why a numerically accurate model might still miss the actual temperature of a real drink.
Evaluation
This project is graded holistically on a 10-point scale. I will look for a correct model and first-step check, a clear comparison of Euler and RK2 at both time steps, a readable graph and error table, and a recommendation that distinguishes numerical error from limitations of the cooling model.
Before submitting
- Render from a fresh R session and inspect the HTML output.
- Check that every run ends at 12 minutes and uses the same model parameters.
- Label temperatures in °C and time in minutes.
- Submit both the
.qmdand.htmlfiles to Moodle.