Teaching · Laboratories

Do not click Run yet.

The laboratories are most useful after a prediction has been made. Otherwise the animation can become a very pretty way to watch the computer tell us something we never bothered to think about.

For each lab, I would ask three kinds of questions. First, what should happen before we run anything? Second, what parameter or assumption should we change while everyone can see the consequence? Third, what explanation survives after the graph has moved? The notes below are built around that sequence.

There is no requirement to use every prompt. In fact, trying to use every prompt would be a fine way to turn a useful demonstration into a hostage situation. Pick the one that exposes the assumption you want students to notice that day.

Root finding

Bisection

Open laboratory →

Before we run it

Give students the initial interval and tolerance. Ask whether the interval is legal for bisection and how many halvings they expect before the width falls below the tolerance.

Change this in public

Run the prepared case first, then replace the function with one of their own. Stop after the first midpoint and make the sign test explicit before allowing the playback to continue.

Ask afterward

What exactly guarantees progress here? Which part of that guarantee disappears if the endpoint signs agree or the function is discontinuous?

Root finding

Newton's method

Open laboratory →

Before we run it

Show the function, derivative, and starting value but not the first iterate. Ask where the tangent should meet the x-axis and whether that looks like an improvement.

Change this in public

Play the tangent construction one step at a time. Then move the starting point to a place where the derivative is small or where the tangent points away from the root.

Ask afterward

Was the failure caused by Newton's formula, the starting information, or the shape of the function near the iterate?

Root finding

Secant method

Open laboratory →

Before we run it

Ask what information we lose when we remove the derivative from Newton's method and what the two function values have to do instead.

Change this in public

Pause on a secant chord and compare its slope with the tangent slope Newton would have used. Then choose two points producing a nearly horizontal chord.

Ask afterward

When does avoiding the derivative help enough to justify a less reliable slope estimate?

Root finding

Bisection vs. Newton vs. Secant

Open laboratory →

Before we run it

Have students predict an ordering before the graph appears, but require them to say what they mean by faster: iterations, function evaluations, derivative evaluations, or wall-clock work.

Change this in public

Use the same function and tolerance for all three. Then choose a starting value that changes Newton's behavior without changing the root.

Ask afterward

Which method used more information? Which method made stronger assumptions? Does the iteration count still settle the comparison?

Differentiation

Finite differences

Open laboratory →

Before we run it

Ask whether making h smaller should always improve the derivative estimate. Most students will know what the expected answer is. Make them explain the mechanism anyway.

Change this in public

Shrink h across several orders of magnitude while the forward, symmetric, and Richardson estimates move toward and eventually away from the exact derivative.

Ask afterward

Where did truncation error stop being the dominant problem and floating-point subtraction begin to matter?

Interpolation

Polynomial, piecewise linear, and spline interpolation

Open laboratory →

Before we run it

Show the data points and ask what all three interpolants must agree on. Then ask what, if anything, forces them to agree between the data.

Change this in public

Move one y-value substantially. Watch the global polynomial react everywhere while the piecewise methods respond more locally.

Ask afterward

If every curve passes through every point, what additional criterion are we really choosing when we choose an interpolation method?

Integration

Simpson's rule

Open laboratory →

Before we run it

Draw one panel with its left endpoint, midpoint, and right endpoint. Ask why three values are enough to determine the quadratic used by Simpson's rule.

Change this in public

Play panels one by one and keep the running area visible. Then increase m and compare how the quadratic pieces follow a curved integrand.

Ask afterward

What does increasing m actually change about the local approximation, and what does it cost?

Integration

Gauss-Legendre quadrature

Open laboratory →

Before we run it

Ask students where they would place five evaluations if they were trying to integrate a smooth function well. Most will spread them evenly.

Change this in public

Reveal the Gaussian nodes and weights, then compare the same integrand with Simpson's rule using a similar number of function evaluations.

Ask afterward

Why is uniform spacing convenient rather than automatically optimal?

Integration

Monte Carlo integration

Open laboratory →

Before we run it

Ask whether doubling the sample size should double the number of correct digits. Do not let a vague answer about 'more samples' pass.

Change this in public

Hold the function fixed and change only the seed. Then hold the seed fixed and increase m while watching the running estimate wander.

Ask afterward

What kind of confidence does Monte Carlo give us that a deterministic quadrature rule does not?

Linear algebra

Jacobi vs. Gauss-Seidel

Open laboratory →

Before we run it

Show A and b before the residual plot. Ask students to inspect the diagonal and predict whether the iterative methods have any reason to behave nicely.

Change this in public

Run a diagonally dominant example, then weaken the diagonal until the residual histories change character.

Ask afterward

What changed in the matrix before anything changed in the graph?

Differential equations

Euler, midpoint, and RK4

Open laboratory →

Before we run it

Give the initial condition and step size. Ask how many slope evaluations each method buys per step and what that extra work is supposed to purchase.

Change this in public

Play one RK4 step slowly enough to identify all four internal slope evaluations. Then halve h and compare all three trajectories.

Ask afterward

Was the improvement caused by more steps, a better step, or both?

Partial differential equations

Heat equation

Open laboratory →

Before we run it

Show alpha, dx, and dt and ask students to compute the FTCS coefficient before displaying the solution.

Change this in public

Run a stable case first. Then increase dt enough to violate the stability condition and play the same initial temperature profile again.

Ask afterward

The differential equation did not change. What numerical assumption did?

Partial differential equations

Wave equation

Open laboratory →

Before we run it

Ask for the Courant number and a prediction about stability. Then ask what a wave should preserve that diffusion does not.

Change this in public

Use a smooth wave first, then a sharp pulse. Finally push the Courant number past the stable range.

Ask afterward

Which artifacts come from the physical model, which come from the grid, and which come from an unstable discretization?

Optimization

Golden-section search

Open laboratory →

Before we run it

Show the interval and the two interior probes. Ask which side should be discarded after the function values are known.

Change this in public

Play the interval reduction on a unimodal function, then reuse the same interval on a multimodal one.

Ask afterward

What assumption about the objective made the interval reduction sensible in the first case?

Optimization

Gradient descent

Open laboratory →

Before we run it

Show the objective, gradient, starting point, and step size. Ask which direction the first update should move and whether the chosen h looks conservative.

Change this in public

Increase h until the path begins to overshoot. Then reduce it until convergence is painfully slow.

Ask afterward

The gradient tells us a direction. What tells us how far to trust it?

Optimization

Simulated annealing

Open laboratory →

Before we run it

Tell students that the algorithm may accept a worse point. Ask why any optimization method would be designed to do something so obviously wrong.

Change this in public

Run the same objective with several seeds. Then change the cooling rate and watch when the search stops taking bad moves seriously.

Ask afterward

When did an uphill move help, and when did it merely waste time?