📘 CodingMarble Learn

Computer Simulation

A model is a simplified description of a real system that keeps only what matters. A computer simulation runs that model step by step in time to see what would happen. It has variables (the state), rules (how the state changes), parameters (numbers we can set) and often randomness, so we repeat runs and average. We check a simulation against real data (validation). Simulations are used for weather, traffic, disease spread, flight training and design, because they are cheaper, safer and faster than real tests, but they are only as good as their model and data.

🎬 Step-by-step story

  1. A class of 49 children. One has a cold. Will everyone catch it? We cannot test this on real children. So we build a model.
  2. A model keeps only what matters. Each child is a block. The rule: a sick child can pass the cold to the 4 children next to them.
  3. A simulation runs the model step by step. Each step is one day. Watch the red spread. The counter shows how many are sick.
  4. Parameters are numbers we can change. Set the chance of passing it on to 20%. The cold spreads slowly now. Same rules, new number, new result.
  5. Chance makes each run different. So we run it many times and take the average. Then we compare with real data to check the model.
  6. Your turn: set the chance and the days, then press Run. Predict first: how many will be sick after 10 days?

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why not just test it in real life?

Real tests can be dangerous, slow or costly, like letting a cold spread in a class. A model lets us test safely.

Isn't a model too simple to be useful?

It keeps only what matters for the question. Blocks and a 4-neighbour rule are enough to show how fast a cold spreads.

What makes it a simulation and not just a model?

Time. The simulation applies the rules again and again, one day per step, and you watch the state change.

Why do I get a different answer each time I press Run?

The rule uses chance. That is why we do many runs and take the average, like the bars in step 5.

How do we know the simulation is right?

We compare its results with real data (validation) and fix the rules or parameters if they disagree.

What does changing a parameter do?

Same rules, different number, different result. Lowering the chance to 20% slows the spread.

What are models and simulations?

A model is a simple copy of a real thing that keeps only the parts that matter for our question. A map is a model of a city. A spreadsheet that works out pocket money is a model of your savings.

A computer simulation is a program that runs a model through time, step by step, to see what would happen. The model is the recipe; the simulation is cooking it.

Why simplify?

The real world has too many details. If we kept every detail the program would be too slow and we could not understand it. So we make assumptions, for example "every child meets only 4 neighbours". Good assumptions keep what matters and drop the rest.

Building a simulation: variables, rules and parameters

A simulation is basically a loop:

set start state → repeat: apply rules, time = time + step, record results → show graph

Randomness

Many real events depend on chance. A simulation uses random numbers for them. Each run gives a different answer, so we do many runs and look at the average and the spread. This is called a Monte Carlo simulation.

Examples of simulations

Checking a simulation, advantages and limits

Validation: compare the simulation's output with real measurements. If they disagree, change the rules or parameters and test again. Verification: check the program does what the model says (no bugs).

Advantages

Limits

Key formulas and definitions

Worked examples

1. A pond has 100 fish. Each year the number grows by 10%, then 5 fish are caught. Simulate 2 years.

Year 1: 100 × 1.10 = 110, minus 5 = 105. Year 2: 105 × 1.10 = 115.5, minus 5 = 110.5 ≈ 110 fish. Variable: fish count. Rule: × 1.10 then − 5. Parameters: 10% growth, 5 caught, time step 1 year.

2. A traffic simulation is run 5 times with random arrivals. Queue lengths at the end: 8, 12, 10, 9, 11 cars. What should the report say?

Average = (8 + 12 + 10 + 9 + 11) ÷ 5 = 50 ÷ 5 = 10 cars, with results ranging from 8 to 12. Report the average and the range, not just one run.

3. A disease model predicts 500 cases by day 20, but the real count was 200. Give two things to check.

Check the parameters (maybe the chance of spreading is too high, or people meet fewer others) and the assumptions (maybe the model ignores masks, holidays or recovery). Change them and validate again against real data.

Common mistakes

Practice quiz

1. A computer simulation is:
2. A number you set before a run, like the speed limit, is a:
3. Why run a random simulation many times?
4. Comparing results with real data is called:
5. Which is a limitation of simulations?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a computer simulation in simple words?

A program that copies how a real thing behaves, step by step in time, so we can see what would happen without doing it for real.

What is the difference between modelling and simulation?

Modelling is making the simplified description (variables, rules, parameters). Simulation is running that model through time on a computer.

What are examples of computer simulations?

Weather forecasts, traffic planning, disease spread, flight simulators, car crash tests, climate change models and game physics.

Where this is taught

ItalySecondaria di secondo grado – classe 5ª (esame di Stato)Computation, networks and simulation
NetherlandsHAVO 5 (eindexamenjaar)Elective theme: Computational science
NetherlandsVWO 6 (eindexamenjaar)Elective theme: Computational science
Spain2º ESOScientific project
Spain3º ESOScientific project
Spain4º ESOScientific project
Ukraine8 класInformation and information literacy: models and data structures
Ukraine10 класBase module: models, data analysis and visualisation
Japan高校(専門学科)1〜3年Sculpture
South Korea고등학교 2학년Simulation software
Russia9 классTheoretical foundations
Russia11 классTheoretical foundations
Russia11 классInformation technologies

Learn first

Learn next

Related lessons

All Computer Science lessons