Skip to content
Tactiverge

What a simulation is

A simulation steps a model of the world forward in time. Learn what goes into a model, why every model rests on assumptions, and the difference between verifying and validating it.

Lesson 1 of 6 · 25 min · Self-paced · Free

Why simulate?

Before an engineering team builds a robot arm, they want answers. Will the motors be strong enough? How far will the arm sag under a load? What happens if the controller gains are set too high? Building and breaking real hardware to find out is slow, expensive and sometimes dangerous. A simulation lets you ask these questions in software: try a hundred designs in an afternoon, crash a virtual robot without harm, and see quantities, like the force inside a joint, that are hard to measure directly.

Simulations are used to design aircraft, forecast weather, plan spacecraft trajectories and train robot controllers. But a simulation is only as trustworthy as the model inside it and the care taken to check it. This module teaches you to build simple simulations and to question them.

What is inside a simulation?

Every time-stepping simulation has the same ingredients:

  • State: the numbers that describe the system at one instant. For a thrown ball: its height and its velocity. For a two-link arm: two joint angles and two joint speeds.
  • Rules: equations that say how the state changes. Usually these come from physics, such as Newton's second law, F = m · a.
  • Parameters: fixed numbers in the rules, such as mass, gravity or a spring's stiffness.
  • Initial conditions: the state at the start.
  • A time step, dt: how far forward each update jumps.

The simulation repeatedly applies "next state = current state + change over dt". You met this pattern when simulating a cooling cup of tea in Python fundamentals.

Models and assumptions

A model is a simplified description of reality. Simplifying is not a flaw; it is the point. A model that included every air molecule around a thrown ball would be impossible to run. Instead we make assumptions, for example:

  • Gravity is constant, 9.81 m/s², at every height.
  • Air resistance is small enough to ignore.
  • The ball is a point: its size and spin do not matter.

Each assumption makes the model simpler and each one can fail. Ignoring air resistance is fine for a heavy steel ball thrown gently; it is badly wrong for a table-tennis ball or a feather. A good engineer writes the assumptions down, so anyone using the results knows where they stop applying.

A first simulation: a ball thrown upward

A ball is thrown straight up at 12 m/s. How high does it go? The state is height y and velocity v. Each step, the height changes by v · dt and the velocity changes by −g · dt.

G = 9.81   # m/s², assumed constant (model assumption)

def max_height(v0, dt):
    """Step a ball thrown straight up until it stops rising."""
    y, v = 0.0, v0          # the state: height (m) and velocity (m/s)
    while v > 0:
        y = y + v * dt      # new height from current velocity
        v = v - G * dt      # new velocity from gravity
    return y

exact = 12.0**2 / (2 * G)
print(f"exact:      {exact:.4f} m")
for dt in [0.1, 0.01, 0.001]:
    h = max_height(12.0, dt)
    print(f"dt = {dt:<5}  {h:.4f} m   error {h - exact:+.4f} m")

Output:

exact:      7.3394 m
dt = 0.1    7.9482 m   error +0.6088 m
dt = 0.01   7.3996 m   error +0.0601 m
dt = 0.001  7.3455 m   error +0.0060 m

For this simple model there is an exact answer from algebra: the maximum height is v₀² / (2g) = 144 / 19.62 ≈ 7.339 m. That is a gift. It lets us check the simulation.

Verification: solving the equations right

Verification asks: does the program correctly solve the model we wrote down? It is about bugs and numerical accuracy, not about the real world.

The table above is a verification test. Each time dt shrinks by a factor of 10, the error shrinks by about a factor of 10 too, and the result approaches the exact answer. That tells us two things: there is probably no bug, and we know how small dt must be for a given accuracy. If the error had not shrunk, or had settled on some wrong value, we would suspect a mistake in the code.

Ways to verify a simulation:

  • Compare with a case that has an exact solution, as here.
  • Check that results converge as dt gets smaller.
  • Check conservation laws: for example, with no friction, total energy should stay (nearly) constant.
  • Check limiting cases: a mass on a spring that starts at rest at its equilibrium position should never move; with gravity set to zero a thrown ball should never come down.
  • Check units and signs: does the ball fall down, not up?

Validation: solving the right equations

Validation asks a different question: does the model describe reality well enough for our purpose? The only way to answer it is to compare with real measurements.

Our ball model could pass every verification test and still fail validation. Throw a real table-tennis ball upward at 12 m/s and it will not reach 7.3 m, because air resistance, which we assumed away, is large for a light ball. The code is correct; the model is wrong for that ball. For a heavy ball thrown gently, the same model might agree with measurements within a few centimetres.

A handy way to remember the difference:

  • Verification: are we solving the equations right?
  • Validation: are we solving the right equations?

You need both. A perfectly verified simulation of the wrong model gives precise, confident, wrong answers. A model that once matched an experiment, but whose code has a bug, cannot be trusted for any new case.

Validation also has limits. A model validated for throws between 5 and 15 m/s tells you little about a throw at 100 m/s, where new effects matter. Every validated model comes with a range of validity.

Recap

  • A simulation steps a state forward using rules, parameters, initial conditions and a time step.
  • Every model rests on assumptions. Write them down, because they define where the model stops working.
  • Verification checks the code solves the model correctly: exact solutions, convergence as dt shrinks, conservation laws, limiting cases.
  • Validation checks the model matches reality, by comparison with measurements, within a stated range.

Knowledge check

Check your understanding

  1. 1. Which of these is part of a ball simulation's state?
  2. 2. A student checks that their simulation's error shrinks steadily as dt is reduced. What are they doing?
  3. 3. A ball simulation without air resistance matches the exact formula perfectly, but a real table-tennis ball goes much lower. What has failed?
  4. 4. Why should you write down a model's assumptions?

Go further