Skip to content
Tactiverge

Computational Engineering capstone

Model, measure and compare: a household oscillator

Build a pendulum or hanging spring from household items, measure it carefully with uncertainty, simulate it in Python, and judge honestly whether your model explains your data.

About 12 hours · 6 milestones · Self-assessed · Free · Download brief (CC BY 4.0)

Why this project

Engineers rarely trust a simulation until they have compared it with a measurement, and rarely trust a measurement until they know its uncertainty. This capstone takes you through the full cycle with a system you can build at home in minutes: a pendulum (a string with a small weight, such as a bunch of keys) or a mass on a spring (a slinky or a rubber band with a small bag of coins). Everything else is Python using only the standard library, plus paper. Plotting with matplotlib is optional and must be installed separately.

What you will do

1. Define the question and the model

Write one clear question, for example: how does the period of my pendulum depend on its length? State the simplest model you will test. For a pendulum with small swings, the textbook model is a period of 2π·√(L / g). Write down every assumption it makes (small angles, a point mass, no air resistance, a string that does not stretch) and predict which assumption is most likely to fail in your set-up.

2. Measure, with uncertainty

Use a ruler or tape measure and a phone stopwatch. Timing one swing is very inaccurate because your reaction time is a large fraction of it, so time ten swings and divide. For at least five different lengths, repeat each timing at least five times. Record raw data in a CSV file with a header row, such as length_m,trial,time_10_swings_s.

Write Python to read the CSV, compute the mean, standard deviation and standard error for each length, and report results with sensible significant figures. Estimate your length uncertainty separately and say which uncertainty dominates.

3. Fit and check

The model predicts that the period squared is proportional to length. Fit a straight line of period² against length using least squares (write the formula yourself), compute the residuals, and estimate g from the slope. Look at the residuals: are they scattered randomly, or do they curve in a pattern that hints the model is missing something?

4. Simulate

Now write a time-stepping simulation. For a pendulum, the equation of motion is angular acceleration = −(g / L)·sin θ, optionally with a small damping term. For a spring, it is a spring–mass–damper. Here is a semi-implicit Euler step for the spring version:

def step(x, v, m, k, c, dt):
    """One semi-implicit Euler step for a spring-mass-damper."""
    a = (-k * x - c * v) / m
    v = v + a * dt
    x = x + v * dt
    return x, v

x, v = 0.05, 0.0
for _ in range(3):
    x, v = step(x, v, m=0.2, k=40.0, c=0.5, dt=0.01)
    print(f"x = {x:.5f} m, v = {v:.4f} m/s")

which prints:

x = 0.04900 m, v = -0.1000 m/s
x = 0.04705 m, v = -0.1955 m/s
x = 0.04420 m, v = -0.2847 m/s

Measure the simulated period by detecting zero crossings. Verify the simulation first: for small angles it should match the analytic formula. Run a step-size study, showing how the error changes as you shrink the step, and compare plain Euler with semi-implicit Euler over many swings.

5. Propagate uncertainty

Use Monte Carlo: draw many random values of length (and any other uncertain input) from their uncertainty ranges, run the model for each, and report the spread of predicted periods. Then validate: do your measured periods fall inside the predicted spread?

6. Probe an assumption

Choose one assumption and test it deliberately. For example, measure the period at a large starting angle and compare with the simulation, which includes sin θ, and the small-angle formula, which does not.

What good work looks like

The best reports separate three things clearly: what you measured, what your model predicted, and how confident you are in each. If the model and data disagree, that is a finding, not a failure. Say by how much, whether the gap is bigger than your uncertainty, and which assumption you suspect. Never adjust or drop data points to make the fit look better. If you exclude a point, say which one and why, and show the result both with and without it.

Milestones

  1. 01

    Question, model and assumptions

    A one-sentence question, the model equation, a list of its assumptions and a prediction of which is weakest in your set-up.

  2. 02

    Raw data collected

    At least five conditions with at least five repeated trials each, stored in a CSV file with a header row and units.

  3. 03

    Statistics and least-squares fit

    Python code computing mean, standard deviation and standard error, a hand-written least-squares fit, residuals and an estimate of g or k.

  4. 04

    Verified simulation

    A time-stepping simulation checked against the analytic small-oscillation result, with a step-size study and a comparison of two integration methods.

  5. 05

    Validation with Monte Carlo

    Predicted period spread from propagated input uncertainty, compared with the measured values.

  6. 06

    Assumption probe and report

    A deliberate test of one assumption and a report separating measurement, prediction and confidence.

What you hand in

  • The raw CSV data file exactly as recorded, plus a short note on how and when it was collected.
  • Python scripts for analysis, fitting, simulation and Monte Carlo, using only the standard library (matplotlib optional).
  • At least three honest plots or clearly formatted text outputs: measured period against length with error bars, residuals, and the step-size study.
  • A 3–5 page report: question, model, method, results with uncertainty, verification, validation, assumption probe and limitations.

Rubric

Read this before you start. Each criterion has four levels of performance.

Measurement and uncertainty

Beginning
Single measurements with no repeats and no uncertainty.
Developing
Repeated measurements, but uncertainty is missing or computed incorrectly.
Proficient
Five or more repeats per condition; mean, standard deviation and standard error correct; the dominant uncertainty source is identified.
Exemplary
As Proficient, plus the student shows how timing several swings reduces the effect of reaction time, with numbers from their own data.

Fitting and analysis

Beginning
No fit, or a fit produced by a tool with no explanation.
Developing
Least-squares fit is computed but residuals are not examined.
Proficient
Hand-written least squares, residuals plotted or listed and interpreted, and a physical constant estimated with uncertainty.
Exemplary
As Proficient, plus a pattern in the residuals is linked to a specific model assumption and the link is tested.

Simulation verification

Beginning
Simulation is not compared with anything.
Developing
Simulation is compared with the analytic result once, with no step-size study.
Proficient
Simulation matches the analytic result for small oscillations; a step-size study and a comparison of two integration methods are shown.
Exemplary
As Proficient, plus the student explains why plain Euler gains energy over many swings and chooses a step size with a stated error target.

Validation and honesty

Beginning
Model and data are said to agree without a quantitative comparison.
Developing
A comparison is made, but uncertainty is ignored when judging agreement.
Proficient
Monte Carlo spread is compared with measured values; disagreement is quantified and discussed against the uncertainty.
Exemplary
As Proficient, plus any excluded data are reported with reasons and results are shown with and without them.

Code quality and reproducibility

Beginning
Code does not run or is a single unexplained block.
Developing
Code runs but has few functions or comments, and results depend on manual steps.
Proficient
Code is organised into small tested functions and reads the raw CSV; running it reproduces every number in the report.
Exemplary
As Proficient, plus a fixed random seed for Monte Carlo and a README explaining how to reproduce everything from scratch.

Going further

Add a damping model: record how the swing amplitude decays over time (for example, by filming against a ruler with a phone and stepping through frames), fit a damping coefficient, and use root finding to determine the step size at which your simulation's decay rate matches the measured one to within your uncertainty.