Tutorials
A cup of coffee cooling
Updated 3 November 2026 · 5 min read
A cup of coffee left on a desk cools toward the temperature of the room: fast while it is hot, then slower and slower. You will build that as one stock, one flow and two constants, run it, and check the answer against the exact solution. It takes about ten minutes.
What you will build#
The coffee’s temperature is the stock. Heat leaves it through one flow, Heat loss, which is faster the hotter the coffee is compared with the room. Two constants set the room’s temperature and how quickly the cup gives up its heat.
The physics is Newton’s law of cooling: the rate of cooling is proportional to the difference in temperature. Written as a formula,
where τ, the cooling time, is how long it takes to close about two thirds of the gap. You won’t type this equation anywhere. You will draw it, and the builder will write it.
Build it#
Start a new model and set its clock
On the Models page, press New model. In the side panel’s Simulation tab, set Start to 0, End to 60, and Time unit to
minute. The model will now run for an hour of coffee time.- 1Start: when the run begins.
- 2End: when it stops.
- 3Time unit: what the model counts time in. Every rate in the model is per this unit.
Add the stock
Click Stock in the components list, then click the canvas a little left of centre. In the side panel, name it Coffee temperature, give it the unit
°C, and set its starting value to 90.- 1The name you read. In formulas it becomes CoffeeTemperature, shown under the title.
- 2The unit. The builder checks every formula against it.
- 3The starting value: a number, or a formula of constants.
The line dCoffeeTemperature/dt = 0 under the unit says the stock has no flows yet, so nothing changes it. That will change in step 4.
Add two constants
Click Constant and place one above the stock. Name it Room temperature, unit
°C, value 20. Place a second, Cooling time, unitminute, value 10.- 1Room temperature, 20 °C.
- 2Cooling time, 10 minutes.
A constant’s range sets where its slider can go. The defaults are fine for now; set Lowest and Highest to the values you think are believable when it matters.
- 1The value, with a slider to try others.
- 2Lowest: the bottom of the slider’s range.
- 3Highest: the top of its range. Fit to Data searches only between the two.
Draw the flow
Click Flow in the components list, then click the stock: the flow starts there. The editor now asks where it ends. Click empty canvas to the right of the stock. The heat leaves the model, into the room, which the model doesn’t track, so the flow ends in a cloud.
- 1The editor says what it needs next.
- 2The flow starts at the stock.
Give the flow its formula
Select the flow. Name it Heat loss, give it the unit
°C/minute, and write its formula:(CoffeeTemperature - RoomTemperature) / CoolingTime- 1A flow’s unit is its stock’s unit per time unit.
- 2The formula, using the names of the stock and the constants.
As you type, dashed links appear from the stock and the two constants to the flow. They are how the diagram shows what the formula uses.
Run it
Press Run. The stock’s temperature falls from 90 °C and levels off toward 20 °C. Drag the time bar to minute 10 and read the value on the stock.
- 1Play the run.
- 2Drag to any moment.
- 1The coffee’s temperature at the moment the time bar shows: 45.75 °C.
The side panel’s charts show the whole run: the stock falling toward the room, and the flow shrinking as the gap closes.
Check it by hand#
This model has an exact answer, which makes it a good first one. The gap between the coffee and the room starts at 70 °C and shrinks by a factor of e every cooling time:
At 10 minutes that is 20 + 70 × 0.3679 = 45.75 °C, which is what the stock says. At 30 minutes it is 23.49 °C, and at an hour 20.17 °C: the coffee is never quite at room temperature, which is what the formula and the model both say.
- The model, every minute
- Exact answer, every 10 minutes
Show the numbers
| minute | The model, every minute | Exact answer, every 10 minutes |
|---|---|---|
| 0 | 90 | 90 |
| 5 | 62.457 | – |
| 10 | 45.752 | 45.75 |
| 15 | 35.619 | – |
| 20 | 29.474 | 29.47 |
| 25 | 25.746 | – |
| 30 | 23.485 | 23.49 |
| 35 | 22.114 | – |
| 40 | 21.282 | 21.28 |
| 45 | 20.778 | – |
| 50 | 20.472 | 20.47 |
| 55 | 20.286 | – |
| 60 | 20.174 | 20.17 |
Few models have an exact answer. The habit is the point: before you trust a model, find one case you can work out on paper and check that the model agrees. A model that gets the coffee wrong will not get an epidemic right.
Try this#
- Drag Cooling time to 5. The coffee cools twice as fast: at minute 10 it is 29.47 °C, which is 20 + 70e−2.
- Set the coffee’s starting value to 20. Nothing happens. It is already at room temperature, so the flow is zero all the way.
- Set the starting value to 5, iced coffee. Heat loss goes negative and the coffee warms toward the room. One flow handles both directions, because the formula does.
- Open the Equations tab. It shows the stock’s rate of change and the flow’s formula: together, the equation at the top of this page.
What you learned#
You drew a stock, two constants and a flow, wrote one formula, and ran it. You checked the units, and you checked the answer against an exact solution. Every model in these pages is built the same way. The next tutorial adds the other half of modelling: matching a model to what was measured.
See also
- Fitting an outbreak to case dataImport daily case counts, let Fit to Data find the contact rate, and judge how far to trust it.
- StockAn amount that builds up or runs down, changed only by its flows.
- FlowA rate that fills or drains a stock, per unit of time.
- Units as a checkWhy giving everything a unit catches mistakes long before a number looks wrong.