How Science Works

Computer Simulation as a Third Way of Doing Science

Understand how simulations turn equations into virtual experiments, where their errors come from, and the checks that make a result worth believing.

Key takeaways

  • A simulation computes how a modeled system evolves, usually in many small steps or through many random trials.
  • Errors can enter through the model, the numerical method, the input data, rounding and ordinary programming mistakes.
  • Verification asks whether the equations are being solved correctly; validation asks whether they are the right equations for the purpose.
  • Results deserve more trust when they survive finer resolution, varied inputs and comparison with data not used for tuning.
  • Shared code, inputs and settings let others examine and repeat computational work.

A computer simulation takes a model of how something behaves and works out step by step what follows from it. It is often called a third way of doing science, alongside theory and experiment, because it lets researchers explore systems whose equations are too tangled to solve by hand and whose real versions are too big, slow, small or risky to manipulate.

A simulation shows the consequences of assumptions. Whether those consequences match nature has to be checked against observation, and a good share of the craft lies in that checking.

From equations to numbers

Many laws are written as differential equations, which say how quickly something changes at each instant. Computers handle them by cutting time, and often space, into pieces. From the present state they estimate the state a small step later, then repeat.

Take a ball dropped from rest, with g = 9.8 m/s² and no air. The exact distance after 2 s is ½ × 9.8 × 2² = 19.6 m. A very crude method assumes that during each step the speed stays at its value from the start of the step.

Step size 1.0 s
  step 1: distance += 0 × 1.0    → 0 m;     speed → 9.8 m/s
  step 2: distance += 9.8 × 1.0  → 9.8 m;   speed → 19.6 m/s

Step size 0.5 s
  distance after four steps = (0 + 4.9 + 9.8 + 14.7) × 0.5 = 14.7 m

The first run misses by 9.8 m, the second by 4.9 m. Halving the step halved the error. Smaller steps do better, and smarter methods converge much faster. This particular scheme is known as the Euler method.

Many styles of simulation

Style Basic idea Typical use
Grid-based Divide space into cells and update each Fluid flow, heat, weather
Particle-based Track many interacting objects Molecules, star clusters
Monte Carlo Use random sampling Particle paths through matter, risk estimates
Agent-based Give individuals simple rules Traffic, crowds, spread of behavior

A Monte Carlo method replaces an intractable calculation with many random trials. Its statistical error typically shrinks in proportion to one over the square root of the number of trials, so cutting that error by a factor of ten takes about a hundred times as many.

What simulation makes possible

Researchers can follow two galaxies as they merge over spans no observer could witness. They can watch how a protein-sized cluster of atoms jostles over tiny fractions of a second. Engineers can try many wing shapes before building one. Particle physicists simulate how known processes would appear in a detector, so that anything unexpected stands out.

Simulations also let you do what nature will not: switch off one effect and see what changes. If a pattern vanishes when friction is removed from the model, friction is part of the explanation within that model.

They can even reveal behavior that nobody anticipated from the rules. Simple equations for fluid convection led Edward Lorenz to highlight sensitive dependence on initial conditions, where tiny differences in the starting state grow into large differences later.

Where error creeps in

  1. The model. Important physics may be missing or simplified.
  2. Subgrid processes. Anything smaller than a grid cell must be represented by a rule of thumb, often called a parameterization.
  3. Discretization. Finite steps and cells only approximate smooth change.
  4. Rounding. Computers store most numbers with limited precision, and tiny errors can accumulate.
  5. Inputs. Starting conditions and constants carry their own uncertainty.
  6. Bugs. A sign error can produce smooth, plausible and wrong pictures.

Turbulence shows the second item clearly. Swirls occur across a vast range of sizes, and resolving all of them is far too costly for most practical problems. In chaotic systems such as a double pendulum, detailed trajectories soon diverge, although statistical features may remain predictable.

Verification and validation

Verification asks, "Are we solving our equations correctly?" Typical checks include comparing with cases that have exact answers, refining the grid or time step until results stop changing meaningfully, and confirming that conserved quantities such as energy stay constant when they should.

Validation asks, "Do the results agree with reality well enough for this use?" That means comparing with measurements, ideally ones that played no part in setting adjustable values.

Building trust in a simulation result
1 State the model Equations, assumptions and inputs 2 Verify the code Match known exact cases 3 Refine Shrink steps and cells; check stability 4 Validate Compare with independent measurements 5 Report range Vary inputs and show the spread State the model Equations, assumptions and inputs 1 Verify the code Match known exact cases 2 Refine Shrink steps and cells; check stability 3 Validate Compare with independent measurements 4 Report range Vary inputs and show the spread 5

Passing one without the other is not enough. Flawless code can solve the wrong equations, and a flawed code can match one dataset by luck or tuning.

Uncertainty and ensembles

One run gives one answer. To learn how much it depends on uncertain choices, researchers run an ensemble: many simulations with slightly different starting states, constants or model versions. The spread shows sensitivity. If nearly all runs agree on a feature, it does not hinge on those particular choices.

An ensemble cannot reveal an error that every member shares. A narrow spread means the runs agree with each other, which is different from agreeing with the world.

A random-number example

Here is Monte Carlo in miniature. To estimate π, imagine a square with sides of length 2 and a circle of radius 1 fitted inside it. The circle's area is π and the square's area is 4, so a point chosen uniformly at random in the square lands in the circle with probability π/4.

Generate many random points, count the share that satisfy x² + y² ≤ 1, with x and y each drawn between −1 and 1, and multiply by 4. Suppose, as an illustration, that 785 of 1,000 points fall inside.

Estimate of π = 4 × 785 ÷ 1000 = 3.14
Standard error ≈ 4 × √(p × (1 − p) ÷ N), with p ≈ 0.785 and N = 1000
             ≈ 4 × √(0.785 × 0.215 ÷ 1000)
             ≈ 0.052

So a typical run of this size could easily give 3.09 or 3.19. A lucky result of exactly 3.14 would not show that the method is accurate to two decimals. With 100,000 points, the standard error falls to about 0.0052. Reporting that spread along with the estimate is the simulation equivalent of putting uncertainty on a measurement.

There are far better ways to compute π. The point is that the same sampling idea works for problems with many interacting random steps where no neat formula exists.

Is it really an experiment?

People disagree about the "third way" label. Some argue that simulation is a powerful extension of theory, since it only unpacks assumptions. Others note that working with a large simulation resembles experimentation: you vary conditions, observe outputs, hunt for artifacts and are often surprised. Either way, it cannot supply facts about nature that were never put in or derived from what was.

Machine-learned stand-ins, trained to imitate expensive calculations, are increasingly used. They can be much faster, and they raise the same question in a sharper form: how well do they behave outside the cases they were trained on? This area changes quickly, so check recent reviews in your field.

Simulation and experiment together

The most productive arrangement is usually a conversation between the two. A simulation suggests where an interesting effect should appear, and an experiment looks there. The measurements expose a mismatch, and the model is revised. The revised version proposes the next measurement.

Simulations also help design experiments before anything is built. A team can ask whether a planned detector would be able to see the signal it is looking for, given realistic noise, and can test analysis software on simulated data where the right answer is known. If the software cannot recover a signal that was planted deliberately, that is worth learning early.

There is a hazard in the loop. If a model is adjusted each time it disagrees, it can come to match the available data while explaining little. Keeping some observations aside until the tuning is finished, and writing down in advance what the model predicts for them, protects against that.

Making computational work checkable

A simulation described only in a paragraph may be impossible to reconstruct. Good practice is to keep the code under version control, record software versions, settings and random seeds, archive input data and share all of it where law and privacy allow.

Even then, results can differ slightly across machines or when parallel processes add numbers in different orders. The difference between rerunning the same code and confirming a finding independently is explained in reproducibility and replicability.

Questions to ask of a simulation

If you want to try one yourself, start with a problem whose exact answer you know, such as the falling ball above, in a spreadsheet. Shrink the time step and watch the error fall. Only then add something like air resistance, where checking is harder, and keep the simple case as a test that must still pass after every change.

When a striking animation appears in the news, remember that realism of the picture says little about accuracy. Ask what the underlying model assumes, what was adjusted to fit, whether finer resolution changes the conclusion, and which observations it has been tested against. A careful team will usually have answers ready, including where it would not rely on its own results.

Written for 4Sciences with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 49 articles in How Science Works →

Latest news on this topic