# Worksheet: Scientific simulation

*Tactiverge Academy · Computational Engineering, module 4 · https://tactiverge.win/academy/computational-engineering/#scientific-simulation*

Name: ______________________    Date: ____________

## Learning objectives

Tick each one when you can do it without looking at your notes.

- [ ] Model a system as a state that changes according to rules over time.
- [ ] Implement Euler's method to simulate motion under gravity.
- [ ] Test a simulation against a case with a known exact answer.
- [ ] Explain how step size affects accuracy and stability.

## Lesson 1: 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.

Read online: https://tactiverge.win/academy/computational-engineering/scientific-simulation/what-is-a-simulation/

### Check your understanding

1. Which of these is part of a ball simulation's state?
   A) The value of g
   B) The ball's current velocity
   C) The time step dt
   D) The programming language

2. A student checks that their simulation's error shrinks steadily as dt is reduced. What are they doing?
   A) Validation
   B) Calibration
   C) Verification
   D) Extrapolation

3. A ball simulation without air resistance matches the exact formula perfectly, but a real table-tennis ball goes much lower. What has failed?
   A) Validation: the model's assumption of no air resistance is wrong for this ball
   B) Verification: the code must have a bug
   C) Nothing: real measurements are always less accurate than simulations
   D) The exact formula is wrong

4. Why should you write down a model's assumptions?
   A) Because simulations will not run without comments
   B) To make the code longer
   C) Because assumptions make results more accurate
   D) Because they show where the model stops applying, so others do not use it outside that range

### My notes

______________________________________________

______________________________________________

## Lesson 2: Time stepping with Euler's method

Turn a rate-of-change equation into a simulation with Euler's method, measure its error against an exact answer, and extend it to systems with several state variables.

Read online: https://tactiverge.win/academy/computational-engineering/scientific-simulation/eulers-method/

#### Project: Euler by hand and by machine

Work with a pencil, paper, a calculator and Python.

1. By hand, apply Euler's method to the capacitor equation dV/dt = −V / 2, starting from V = 5 V, with dt = 1 s, for 4 steps. Write a table of t, slope and V.
2. Compute the exact values 5 · e^(−t/2) for t = 1, 2, 3, 4 and add them to your table.
3. Check your hand table with the `euler` function from this lesson.
4. Use `euler` on a new equation of your choice, for example Newton's cooling dT/dt = −0.1 (T − 20) from T = 90 °C, and show that halving dt roughly halves the error at t = 10 min. The exact solution is T = 20 + 70 · e^(−0.1t).

**Deliverables**

- A hand-worked table with Euler and exact values
- Python output confirming the hand table
- A table of error against dt for your second equation, with one sentence on the pattern

### Check your understanding

1. With y = 10, dy/dt = −2y and dt = 0.1, what is y after one Euler step?
   A) 8
   B) 12
   C) 9.8
   D) 0

2. Euler's method gives an error of 0.04 at t = 4 s with dt = 0.2 s. Roughly what error do you expect with dt = 0.1 s?
   A) 0.04
   B) 0.01
   C) 0.08
   D) 0.02

3. Why did the Euler simulation of a dropped object underestimate the distance fallen?
   A) Because g was rounded
   B) Because each step used the speed from the start of the step, while the object kept speeding up during it
   C) Because Python tuples lose precision
   D) Because the speed was wrong

4. Why compute the number of steps as round(t_end / dt) instead of looping while t < t_end?
   A) round makes the simulation run faster
   B) It is required by Python
   C) Repeatedly adding a float like 0.1 may not land exactly on t_end, so the while loop could take an extra step
   D) It makes Euler's method second order

### My notes

______________________________________________

______________________________________________

## Lesson 3: Simulating a falling object with air drag

Add air resistance to a falling-object simulation, discover terminal velocity, and verify the simulation against an exact solution.

Read online: https://tactiverge.win/academy/computational-engineering/scientific-simulation/falling-object-with-drag/

#### Project: Validate a drag model with paper cupcake cases

Paper cupcake cases (or coffee filters) fall slowly and stack neatly, so you can change the mass without changing the shape.

1. Measure a fixed drop height of about 1.5–2 m against a wall. Drop from an outstretched arm while standing on the floor; do not stand on chairs or tables.
2. Drop 1, 2, 4 and 8 stacked cases, timing each fall five times with a phone stopwatch. Record every time and compute the mean and standard error for each stack.
3. Weigh a stack of cases on a kitchen scale (or estimate from a packet), measure the diameter, and assume C_d ≈ 1.0 as a starting guess for this shape.
4. Simulate each drop in Python and compare with your measurements. Adjust C_d to fit one stack, then check whether the same C_d predicts the others.
5. Write down every assumption you made and where the model disagrees with reality.

**Deliverables**

- A table of measured fall times (mean ± SE, n = 5) for each stack
- A Python simulation with predicted fall times for each stack
- A short validation note: the fitted C_d, how well it predicts the other stacks, and the main sources of disagreement

### Check your understanding

1. If a ball's speed doubles, what happens to the quadratic drag force on it?
   A) It doubles
   B) It stays the same
   C) It halves
   D) It becomes four times larger

2. What condition defines terminal velocity for a falling object?
   A) The drag force equals the weight, so the net force and acceleration are zero
   B) The object has fallen for exactly one second
   C) The drag force is zero
   D) The speed equals g

3. Two spheres have the same size and shape, but one is 4 times heavier. How do their terminal speeds compare?
   A) The heavier one's is 4 times higher
   B) They are equal
   C) The heavier one's is 2 times higher
   D) The heavier one's is 16 times higher

4. Why compare the simulation with the formula v_t · tanh(g t / v_t)?
   A) To validate the model against reality
   B) To verify that the code solves the drag equation correctly, using a case with a known exact answer
   C) Because Euler's method needs tanh to work
   D) To find the drag coefficient

### My notes

______________________________________________

______________________________________________

## Lesson 4: Simulating a spring–mass–damper system

Simulate the classic model of anything that vibrates, see how damping changes its behaviour, and connect it to how a controlled robot joint responds.

Read online: https://tactiverge.win/academy/computational-engineering/scientific-simulation/spring-mass-damper/

#### Project: Find the fastest settling damping

Using the simulation from this lesson, investigate how damping affects **settling time**: the time after which the mass stays within 2% of its starting displacement (here, within ±2 mm).

1. Write a function `settling_time(c)` that simulates the release from 0.10 m and returns the last time at which |x| exceeds 0.002 m.
2. Compute settling times for ζ = 0.1, 0.2, 0.3, …, 2.0 and print them in a table.
3. Which ζ settles fastest? (You may find it is a little below 1, because a small overshoot that stays inside the band can be acceptable.)
4. Double k and repeat. What happens to the best ζ, and to the best settling time?
5. Explain, in two or three sentences, what this suggests about tuning Kd for a PD-controlled joint.

**Deliverables**

- A settling_time function and a table of settling time against ζ
- The best ζ for both stiffness values
- A short explanation linking the result to PD controller tuning

### Check your understanding

1. A mass of 2 kg hangs on a spring of stiffness 50 N/m. What is its natural frequency ω_n?
   A) 25 rad/s
   B) 5 rad/s
   C) 100 rad/s
   D) 0.2 rad/s

2. A system with ζ = 0.1 is released from rest away from its equilibrium. What will it do?
   A) Return slowly without overshoot
   B) Stay where it is
   C) Return as fast as possible without overshoot
   D) Overshoot and oscillate with gradually shrinking swings

3. For m = 0.5 kg and k = 20 N/m, what damping coefficient c gives critical damping?
   A) About 6.3 N·s/m
   B) 20 N·s/m
   C) 10 N·s/m
   D) 0.5 N·s/m

4. In a PD-controlled robot joint, which gain behaves most like the damper?
   A) The proportional gain Kp
   B) The joint's mass
   C) The derivative gain Kd
   D) The target angle

5. Why might ζ = 2 be a poor choice even though it never overshoots?
   A) It makes the system oscillate forever
   B) It returns to rest sluggishly, taking much longer to settle than a system near ζ = 1
   C) It is impossible to simulate
   D) It increases the natural frequency

### My notes

______________________________________________

______________________________________________

## Lesson 5: Numerical stability and choosing a step size

See how a step that is too large can make a simulation blow up, understand why, fix oscillating systems with semi-implicit Euler, and learn a routine for choosing dt.

Read online: https://tactiverge.win/academy/computational-engineering/scientific-simulation/stability-and-step-size/

### Check your understanding

1. For dy/dt = −20 · y, what is the largest step for which explicit Euler is stable?
   A) 0.2 s
   B) 0.05 s
   C) 0.1 s
   D) 2 s

2. Euler on a decay equation gives values 1, −0.5, 0.25, −0.125, … What does this show?
   A) The system is physically oscillating
   B) The simulation is unstable
   C) The step size is perfect
   D) The method is stable but the step is too large to be accurate, since the true solution never changes sign

3. What is the only difference between explicit and semi-implicit Euler in this lesson?
   A) Semi-implicit Euler updates velocity first, then updates position using the new velocity
   B) Semi-implicit Euler uses a smaller time step
   C) Semi-implicit Euler ignores the spring force
   D) Semi-implicit Euler runs the loop backwards

4. You halve dt and an important result changes by 30%. What should you do?
   A) Report the result from the larger step
   B) Keep halving dt until the result stops changing by more than your tolerance
   C) Average the two results and report that
   D) Conclude the physics is chaotic

### My notes

______________________________________________

______________________________________________

## Lesson 6: Monte Carlo simulation and randomness

Use random numbers to estimate π, see how the error shrinks with more samples, and propagate measurement uncertainty through a calculation or a whole simulation.

Read online: https://tactiverge.win/academy/computational-engineering/scientific-simulation/monte-carlo-simulation/

### Check your understanding

1. In the π estimate, 7,850 of 10,000 random points land inside the quarter circle. What is the estimate of π?
   A) 3.14
   B) 0.785
   C) 7.85
   D) Exactly π

2. A Monte Carlo estimate has a typical error of 0.02 with 10,000 samples. About how many samples are needed for an error of 0.002?
   A) 100,000
   B) 20,000
   C) 1,000,000
   D) 10,000,000,000

3. Why set a random seed in a Monte Carlo program?
   A) It makes the numbers truly random
   B) It makes the result more accurate
   C) It is needed for random.gauss to work
   D) It makes the results reproducible, so others can check them exactly

4. In g = 4π²L/T², why did the 0.5% uncertainty in T matter more than the 0.5% uncertainty in L?
   A) Because T is measured in seconds
   B) Because T is squared, so its relative uncertainty counts twice
   C) Because Monte Carlo favours the last variable
   D) Because L is always measured more accurately

5. What is the main advantage of Monte Carlo over the propagation-of-uncertainty formula?
   A) It works even when there is no simple formula, such as for the output of a whole simulation
   B) It is always faster
   C) It needs no assumptions about the inputs
   D) It gives exact answers

### My notes

______________________________________________

______________________________________________

---

## Answer key (for self-checking after you try)

**Lesson 1: What a simulation is**

1. B — State is what changes over time and describes the system at an instant: here height and velocity. g is a parameter and dt is a setting of the method.
2. C — Checking that the program solves its own equations accurately, for example by convergence tests, is verification. It says nothing yet about whether the equations match reality.
3. A — The code solves its model correctly, so verification passed. The model itself does not describe this light ball, which is a validation failure.
4. D — Each assumption, such as ignoring drag, is true only in some situations. Recording them lets users judge whether the model fits their case.

**Lesson 2: Time stepping with Euler's method**

1. A — The slope is −2 × 10 = −20, so y_next = 10 + (−20)(0.1) = 8.
2. D — Euler is first order, so the error is roughly proportional to dt. Halving dt roughly halves the error, to about 0.02.
3. B — The object is faster at the end of each step than at the start, so using the start speed for the whole step always falls short.
4. C — Floats are approximate. For example, adding 0.1 ten times gives 0.9999999999999999, just below 1.0, so a loop of while t < 1.0 would run an eleventh time.

**Lesson 3: Simulating a falling object with air drag**

1. D — Drag is proportional to v², so doubling v multiplies drag by 2² = 4.
2. A — When drag balances weight there is no net force, so the speed stops changing. Solving ½ρC_dAv² = mg gives the terminal speed.
3. C — v_t = √(2mg / (ρC_dA)) is proportional to √m, so 4 times the mass gives √4 = 2 times the terminal speed.
4. B — Matching an exact solution of the same equations checks the code and step size. Comparing with real drops is the separate validation step.

**Lesson 4: Simulating a spring–mass–damper system**

1. B — ω_n = √(k/m) = √(50/2) = √25 = 5 rad/s.
2. D — ζ < 1 is underdamped: the damper is too weak to stop the mass overshooting, so it oscillates while the amplitude decays.
3. A — Critical damping is 2√(km) = 2√(20 × 0.5) = 2√10 ≈ 6.32 N·s/m.
4. C — The derivative term produces a torque opposing angular velocity, just as a damper produces a force opposing velocity. Kp acts like the spring.
5. B — Heavy damping resists all motion, including the motion back to rest. In the simulation the ζ = 2 mass was still 0.7 mm away after 3 s, while ζ = 1 had settled by about 1.5 s.

**Lesson 5: Numerical stability and choosing a step size**

1. C — Stability needs dt ≤ 2 / k = 2 / 20 = 0.1 s. To avoid sign flips as well, dt ≤ 1 / k = 0.05 s.
2. D — An amplification factor of −0.5 still shrinks the value (stable), but the sign flips are a numerical artefact. A smaller step would give a smooth decay.
3. A — Using the freshly updated velocity in the position update is enough to stop the steady energy growth of explicit Euler on oscillators.
4. B — A large change means the result has not converged. Only once further refinement barely changes it can you trust the step size.

**Lesson 6: Monte Carlo simulation and randomness**

1. A — π ≈ 4 × 7850 / 10000 = 4 × 0.785 = 3.14.
2. C — Error falls as 1/√N, so a 10 times smaller error needs 10² = 100 times as many samples: 1,000,000.
3. D — A seed fixes the pseudo-random sequence. The same seed always gives the same numbers, which makes results checkable and bugs traceable.
4. B — For a quantity raised to a power, its relative uncertainty is multiplied by that power. T² doubles T's 0.5% to 1%, while L contributes only 0.5%.
5. A — Monte Carlo only needs to run the model repeatedly. It still requires assumed input distributions, and it is slower, but it handles any model, however complicated.

---

This work is licensed under the Creative Commons Attribution 4.0 International licence (CC BY 4.0): https://creativecommons.org/licenses/by/4.0/. Attribute as: Tactiverge Academy, https://tactiverge.win.
