Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 46 ยท The Modelling Cycle

Solving, Interpreting and Iterating

Solve the cooling model by formula and code, read what the answer means in plain words, fit it to data, and use residuals to decide how to improve the model.

You have a model. Now you must get an answer out of it, decide whether to believe the answer, and say what it means to someone who has never seen the equation. This lesson covers the last three steps of the cycle: solve, check, report, and the arrow that sends you back to the start.

What you will learn

  • How to solve dT/dt = โˆ’k (T โˆ’ T_env) exactly, and why code is a second opinion
  • How to translate a solution into plain-language facts such as half-life
  • How to fit a parameter to data and read the residuals
  • How residuals reveal what the next lap of the cycle should add

Key terms

Analytic solution: an exact formula for the answer.

Half-life (of the excess): the time for the gap T โˆ’ T_env to halve.

Residual: data value minus model prediction. Patterns in residuals expose missing physics.

RMSE: root mean square error, a single number summarizing the size of residuals.

Iteration: another lap of the cycle with an improved model.

Solving by formula

The equation dT/dt = โˆ’k (T โˆ’ T_env) is separable. Write D = T โˆ’ T_env, the excess temperature. Since T_env is constant, dD/dt = โˆ’k D. The solution is exponential decay:

D(t) = Dโ‚€ e^(โˆ’kt), so T(t) = T_env + (Tโ‚€ โˆ’ T_env) e^(โˆ’kt)

With Tโ‚€ = 90 ยฐC, T_env = 21 ยฐC and k = 0.06 per min: T(t) = 21 + 69 e^(โˆ’0.06 t).

To get the time to reach 60 ยฐC, solve 21 + 69 e^(โˆ’kt) = 60: e^(โˆ’kt) = 39/69, so

t = โˆ’ln(39/69) / 0.06 โ‰ˆ 9.5 min

A cooling curve from 90 degrees toward 21 degrees with measurement dots near it and the point where the coffee reaches 60 degrees after about 9.5 minutes
The curve is the model's prediction. The dots are illustrative measurements. The marked point answers the original question.

Interpreting: from symbols to sentences

A result is not finished until you can say it in words a non-mathematician can use. Here are three translations of the same solution:

  • Answer: the coffee reaches 60 ยฐC after about 9.5 minutes.
  • Half-life of the excess: tยฝ = ln 2 / k = 0.693 / 0.06 โ‰ˆ 11.6 min. Every 11.6 minutes the gap to room temperature halves: from 69 to 34.5 to 17.3 and so on.
  • Time constant: ฯ„ = 1/k โ‰ˆ 16.7 min. After one time constant the gap has dropped to about 37% (eโปยน) of its start.

Also describe the long-term behavior: the coffee never quite reaches 21 ยฐC in this model but gets as close as you like. And mention the limits of the answer: it holds for a stirred cup in a steady room.

Python Formula versus numerical solution, with plain-language facts

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Checking: units, limits, data

Before you trust any number, run a short checklist:

  1. Units: k has units 1/min, so kt is dimensionless and can go inside exp. โœ“
  2. Limits: at t = 0 we get Tโ‚€ โœ“; as t โ†’ โˆž we get T_env โœ“; and the curve decreases, as hot coffee does โœ“.
  3. Order of magnitude: 9.5 minutes feels plausible for a cup.
  4. Data: the real test. Compare predictions with measurements.

Fitting k to measurements

Suppose you stand next to the cup with a thermometer and record the temperature every 2.5 minutes. The data below are made-up measurements for practice; they come from a slightly more complicated "hidden truth" than our model (the mug itself warms up and absorbs heat), as in real life. You fit k by choosing the value that minimizes the squared error, which scipy.optimize.curve_fit does for you. Then you look at the residuals.

Python Fit the model and read the residuals

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

If the model were complete, residuals would look like random noise, scattered above and below zero with no pattern. Instead you should see a clear run of one sign, then the other: a systematic misfit. The model is right in spirit but missing something.

Iterating: the next lap

That pattern is a hint from the data about what the next lap needs: two different time scales, a fast one (the mug absorbing heat) and a slow one (the whole cup losing heat to the room). Update the assumptions: the mug and coffee are two separate heat stores. The simplest equation that captures this is a sum of two exponentials:

T(t) = T_env + Aโ‚ e^(โˆ’kโ‚ t) + Aโ‚‚ e^(โˆ’kโ‚‚ t), with Aโ‚ + Aโ‚‚ = Tโ‚€ โˆ’ T_env

Python Lap 2: a two-exponential model

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Lap 2 fits better, but notice what you gained and what you paid. You gained accuracy. You paid with two extra parameters, which means two more things to estimate and two more ways to overfit. Stop iterating when the model is accurate enough for the purpose defined in step 1, not when the fit reaches perfection.

Reporting

Finish with a short, honest report, in this shape:

  1. Answer: "About 9.5 minutes from the lap 1 model, though the residuals suggest the real cup cools faster early on."
  2. Method: "Newton's cooling law with k fitted to a thermometer experiment."
  3. Limits: "Assumes a stirred cup and a steady room; the early drop is faster than the model predicts."
  4. Next step: "Add a second time scale for the mug, as in lap 2."

Common misconceptions

"Exact formula means exact answer." The formula is exact for the model. The model is still an approximation of the cup.

"A good fit proves the model." A flexible model fits almost anything. Residuals and out-of-range tests are more informative than a single fit.

"More parameters is always better." Each parameter must be earned by evidence that the simpler model fails.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. The solution of dT/dt = -k (T - T_env) with T(0) = T0 is:

    The excess temperature decays exponentially, starting from T0 - T_env.
  2. 2. With k = 0.06 per minute, the half-life of the excess temperature is about:

    Half-life = ln 2 / k = 0.693 / 0.06, about 11.6 minutes. The number 16.7 minutes is the time constant 1/k.
  3. 3. What does a run of positive residuals followed by a run of negative residuals suggest?

    Residuals from a complete model look random. A pattern means something structural is missing.
  4. 4. When should you stop iterating on a model?

    The purpose from step 1 sets the accuracy you need. Chasing perfection adds parameters without value.
  5. 5. In the report, why include the model's limits?

    An answer without its limits invites misuse.

Summary

  • The cooling equation solves to T = T_env + (Tโ‚€ โˆ’ T_env) e^(โˆ’kt); a numerical solver gives the same values.
  • Translate results into plain facts: time to target, half-life ln 2 / k, time constant 1/k.
  • Check units, limits, order of magnitude and data; fit parameters with least squares.
  • Patterned residuals show what to add in the next lap, but every added parameter must earn its place.
  • Report the answer with method, limits and next step.

Next: Chapter 2 Review