Skip to main content

8.4b ODE algorithm labs

Source: Lab ideas from Computational Physics (Landau, Páez, Bordeianu), §8.4. Original drills with float-locked answers. Continues 8.4 ODE algorithms.

Explorer​

Pure Python (math OK). No NumPy / VPython. Stubs fail until filled.

Shared oscillator. m=1m=1, k=(2π)2k=(2\pi)^{2} so ω=2π\omega=2\pi, T=1T=1. IC x=0x=0, v=1v=1. Analytic amplitude A=1/ωA=1/\omega. Force F=−kxF=-kx. Energy E=12v2+12kx2E=\tfrac12 v^{2}+\tfrac12 k x^{2}.

Formula refresh​

Warm up: pick the matching equation among lookalikes (same walk as the theory lesson).

Labs​

Activity: Euler one step

Take one Euler step with h=0.01h=0.01 from (x,v)=(0,1)(x,v)=(0,1). Print x v with 10 decimals.

No input.

Write-ups​

0/4 solved
8.4b.W1

Using “Euler”, “tangent”, and “local”, explain:

In one sentence, why does a single Euler step from (0,1) leave v unchanged for F=−kx?

Minimum 3 words. Your answer must include: “Euler”, “tangent”, “local”.

0 words/ 3 min

Meet the writing requirements, then you can open the model answer.

Explorers​

# harmonic_rk_compare_sketch.py — original structure (no VPython)
import math

def rk2_step(x, v, h, k, m=1.0):
def f(x, v):
return v, -k * x / m
f0, f1 = f(x, v)
k1x, k1v = h * f0, h * f1
f0, f1 = f(x + 0.5 * k1x, v + 0.5 * k1v)
return x + h * f0, v + h * f1 # equivalent to y+k2

# Compare x(0.25) from Euler / RK2 / RK4 vs A*sin(ω*0.25)

Next: 8.5 Nonlinear oscillation solutions.