A cup of coffee at 100 degrees stands in a room at 20 degrees. Newton's observation was that it loses heat at a rate proportional to how much hotter it is than the room. Write y for its temperature and take the constant of proportionality to be k = 1/4 per minute.
Definition · Newton's law of coolingA body at temperature y in surroundings at the constant temperature A obeys y′ = −k·(y − A) for a constant k > 0.
It assumes the surroundings stay at A and the body has one temperature throughout. The lab computes what follows from those assumptions; it does not check them for a real cup.
y′ = −(1/4)·(y − 20), y(0) = 100
u = y − 20 u(0) = 80
u′ = y′ = −(1/4)·u
u = 80·e^(−t/4)
y = 20 + 80·e^(−t/4)
The check is by differentiating: the rate of 20 + 80·e^(−t/4) is −20·e^(−t/4), and −(1/4)·(y − 20) = −(1/4)·80·e^(−t/4), the same. The temperature at time t is a rounded number, since e^(−t/4) is irrational for t ≠ 0, which is why a check by differentiating is the right check and an evaluation is not.
The rate is not constant
Run Euler's method with a step of one minute. The first step uses the starting rate −(1/4)·(100 − 20) = −20, so y₁ = 80. The gap is now 60 and the rate −15, so y₂ = 65. Then the gap is 45 and the rate is −45/4, so y₃ = 215/4. The rate changes at every step because the gap does.
step n gap yₙ − 20 rate −(1/4)·(yₙ − 20)
0 80 −20
1 60 −15
2 45 −45/4
3 135/4 −135/16
each gap is the one before times 3/4 = 1 − kh
The gap is multiplied by 1 − kh = 1 − 1/4 = 3/4 at every step (the lab's factor tile, which takes the signed rate −1/4, writes the same number as 1 + kh), so yₙ = 20 + 80·(3/4)ⁿ. At n = 4 that is 20 + 80·81/256 = 725/16, which is 45.3125, and the lab prints it exactly. The closed form at t = 4 is 20 + 80·e^(−1), which the lab prints rounded: ≈ 49.4304. The two differ because a step of one minute assumes the rate stays put for the whole minute, while the true rate keeps falling. The lab's error tile prints the gap as ≈ 4.11786, rounded, and it is the method's error at this step size and no other.
The same equation warms a cold cup
A cup at 5 degrees in a room at 20 has a gap of 5 − 20 = −15, a negative gap, and the rate −k·(−15) is positive. Nothing else changes. With k = 1/2 and a step of 1 the factor is 1/2, so the gap is cut in half at every step: −15, −15/2, −15/4, …. The temperatures 5, 25/2, 65/4, 145/8, 305/16, … climb towards 20 and none of them passes it; the lab's closed form at the fourth step is ≈ 17.97, rounded. The third preset is a drink at 25 degrees in a fridge at 4: the gap is 21, the factor is 9/10, and the steady-state tile reads 4.
Example · How long until the gap halvesThe gap follows u₀·e^(−kt), so it halves in ln 2/k, the half-life of the previous lesson. For k = 1/4 that is 4·ln 2 ≈ 2.77259 minutes, and then the coffee is at 20 + 40 = 60 degrees. With the target set to 60, the lab prints the first step of the exact sequence at or below 60: step 3 (t = 3), where the sequence is at 215/4 = 53.75, having been at 65 one step earlier.