Mathematical Modelling (Coding)
Mathematical modelling through coding transforms abstract maths into concrete problem-solving tools that Year 8 students can visualise and test. When pupils write code to model real-world scenarios—from calculating bus journey times to tracking savings growth—they develop both computational thinking and mathematical reasoning skills simultaneously.
Try it right now
Click “Generate a problem” to see a fresh example of this technique.
Why it matters
Mathematical modelling with code bridges the gap between theoretical maths and practical applications across GCSE subjects. Students who model population growth with loops understand exponential functions more deeply, whilst those coding distance-time relationships grasp linear equations intuitively. In computer science GCSE, algorithmic thinking combines with mathematical concepts to solve authentic problems. A Year 9 pupil modelling mobile phone tariffs (£20 monthly plus £0.15 per minute) gains practical numeracy skills alongside programming logic. These models help students test hypotheses systematically—running 100 iterations to find optimal solutions rather than guessing. The approach particularly benefits kinesthetic learners who struggle with abstract algebraic manipulation but excel when they can experiment with code, adjust parameters, and observe immediate results across multiple scenarios.
How to solve mathematical modelling (coding)
Modelling with Code
- Identify the real-world relationship to model.
- Write a formula or rule as code (e.g. y = 2*x + 3).
- Use loops or iteration to test multiple inputs.
- Compare the model's output to real data to check accuracy.
Example: Model: cost = 5 * items + 10. For 3 items: cost = 25.
Worked examples
A jar has 27 marbles. You add 7 marbles each round for 2 rounds. How many marbles total?
Answer: 41
- Set up the model → total = 27 + 7 x 2 — Start + added marbles.
- Calculate → total = 27 + 14 = 41 — After 2 iterations.
An airplane flies at 748 km/h. How far does it travel in 5 hours?
Answer: d = 748 x 5 = 3740 km
- Write formula → d = 748 x t — distance = speed x time.
- Substitute → d = 748 x 5 = 3740 — The airplane travels 3740 km.
A radioactive sample has 500 atoms. Each hour 2% decay. Model 5 hours.
Answer: 454
- Set up loop → p = 500; repeat 5: p = p - p x 2/100 — Subtract the decay percentage each hour.
- Trace values → 500 -> 490 -> 481 -> 472 -> 463 -> 454 — After 5 iterations: 454.
Common mistakes
- Students often confuse the model setup with the calculation, writing total = 25 + 8 × 3 = 49 directly instead of recognising this represents total = start + (rate × steps) where start=25, rate=8, steps=3.
- When coding percentage decay, pupils frequently subtract the percentage value rather than the calculated amount, writing amount = 400 - 5 instead of amount = 400 - (400 × 5/100) = 380.
- Students mix up the order in distance-speed-time models, calculating speed = distance × time to get 240km/h instead of speed = distance ÷ time = 60km/h for 240km in 4 hours.
- In greedy allocation problems, pupils often split budgets equally rather than maximising one item first, buying 3 of each item for £120 instead of buying 8 expensive items and 2 cheap ones for optimal value.