← All days ◀ Day 13Day 15 ▶
15-Day Differential Equations Course · Week 3 · Day 14

Modelling Studio: Fitting Models to Data

A model is only as good as its parameters. Learn the modelling cycle, from question to validated equation; fit ODE parameters to measured data by least squares; use the rate plot to choose the right model before fitting; and read residuals to know when the model is missing physics. Real data from a test rig, a cup of tea, an epidemic and a coasting rotor.

⏱ about 2–3 hours🧪 Lab: Model fitter❓ 5-question quiz

1Today's goals

  • Follow the modelling cycle: question, assumptions, equation, fit, validate, use
  • Non-dimensionalise to find the time scales that matter
  • Fit ODE parameters by least squares and judge the fit from residuals
  • Use the rate plot y′ against y to choose a model
  • Turn a fitted model into a decision — when is a test "stabilised"?

2The modelling cycle

  1. Ask a precise question. "When will the oil temperature be stable enough to take readings?" is a modelling question; "model the gearbox" is not.
  2. List assumptions. Well-mixed oil, constant load, constant room temperature, heat loss proportional to temperature rise.
  3. Write the balance. m·c·T′ = Ploss − h·A·(T − Troom) — a first-order lag.
  4. Non-dimensionalise. Find the natural scales (here τ = m·c/(h·A) and ΔT = P/(h·A)); they show which parameters matter and which terms are negligible.
  5. Fit the unknown parameters to data.
  6. Validate on data you did not fit — a different run, a different load.
  7. Use the model, and say how far it can be trusted.

3Least squares for ODE models

Given measurements (ti, yi) and a model y(t; p) obtained by solving the ODE with parameters p, choose p to minimise

S(p) = Σ ( yi − y(ti; p) )²

For an ODE there is usually no formula for the best p, so a search algorithm adjusts p, re-solves the ODE, and repeats: Nelder–Mead (used in the lab), Gauss–Newton or Levenberg–Marquardt. Report the fit with its RMS error and R², and always look at the residuals yi − y(ti; p): they should look like noise. A smile, a wave or a trend means the model is wrong, however high R² is.

Identifiability and over-fitting

Some parameter combinations cannot be told apart from the data. In SIR fitted only to the early, exponential phase, the data fixes β − γ (the growth rate) but not β and γ separately — many pairs fit equally well and predict very different peaks. That is practical non-identifiability; the cure is better data (the turning point) or prior knowledge (the known infectious period). Adding parameters always reduces S on the fitted data; judge models with fresh data, or penalise complexity (AIC, BIC).

4The rate plot: choose the model before you fit

For an autonomous first-order model y′ = f(y), estimate the slope of the data by finite differences, (yi+1 − yi−1)/(ti+1 − ti−1), and plot it against y. The points trace out f itself:

Shape of y′ against yModel
Straight line falling through zero at y∞First-order lag: y′ = (y∞ − y)/τ, slope −1/τ
Straight line through the originExponential growth or decay
Upside-down parabola through 0 and KLogistic
A curve bending down at large yQuadratic loss, e.g. windage: ω′ = −a − bω²

It turns a curve-fitting guess into a picture of the differential equation itself — the theme of this course.

5Worked example

Gearbox oil on an endurance rig: fitted T∞ = 78 °C, T(0) = 32 °C, τ = 22 min. The procedure says "record when T changes by less than 1 °C in 30 min". When is that?T(t) = 78 − 46·e^(−t/22) rate T′ = (46/22)·e^(−t/22) = 2.09·e^(−t/22) °C/min Criterion: T′ < 1/30 = 0.0333 °C/min e^(−t/22) < 0.0333/2.09 = 0.0159 → t > 22·ln(62.7) = 22 × 4.14 = 91 min Equivalently, the criterion is met when 46·e^(−t/22) < 22/30 → within 0.73 °C of T∞ (about 4.1 τ). This reads the criterion as an instantaneous rate. If the procedure means "the reading changed by less than 1 °C over the last 30 min", the change over that window is 46·e^(−(t−30)/22)·(1 − e^(−30/22)) < 1 → t > 30 + 22·ln(34.2) = 108 min. Write down which reading your procedure means. A fit on the first 30–40 min already predicts T∞ and the ready time — the rest of the warm-up can be used for something else.
Rotor run-down: why ω′ = −a − b·ω²?Bearing and seal friction give a roughly constant torque → −a Air drag (windage) torque grows with speed squared → −b·ω² At high speed the coast-down curve is dominated by windage (curving), at low speed it ends in a straight line (friction). Fitting a and b separates the two losses — a standard test on turbo-machinery.
Where you meet thisThermal stabilisation of test rigs and machine tools, battery capacity fade, drug pharmacokinetics (fitting absorption and elimination rates), epidemic forecasting, market adoption, creep and relaxation tests, tyre and brake temperature models, and digital twins — which are exactly "an ODE model kept fitted to live data".

6Lab: model fitter

Choose a data set. Edit the parameters by hand and watch three plots: data and model, the rate plot (data slopes against the model's f), and the residuals. Then press Auto-fit. Choose "Your own data" and paste two columns (time, value) from a spreadsheet to fit your own rig or process.

7Pro tips and common mistakes

  • Finite-difference slopes amplify noise. Sample often enough, average, or smooth before the rate plot — never before the fit itself.
  • Fit in the units the data was measured in; check that parameters come out physically sensible (positive time constants, capacities above the data).
  • A model that fits one run is a hypothesis. A model that predicts the next run is knowledge.
  • Keep the model as simple as the question allows. A first-order lag that is good to ±1 °C is worth more than a twelve-parameter model nobody can check.

8Practice

  1. In the lab, fit the oil data, then change τ by ±20 % by hand. How do the residuals change shape?
  2. Fit the tea data with the first-order lag model instead of Newton cooling. Do you recover room temperature as y∞?
  3. Fit the SIR data. What is R₀? Now imagine you only had the first 30 days — would β and γ be well determined?
  4. Paste a warm-up log from a real machine (time in minutes, temperature) and find its τ.

9Quick quiz

5 questions. Click an answer — you get the explanation straight away.

Progress is kept in this browser (and in your account when signed in).