Solving ODEs 🌊

From Newton's falling apple to chaotic double springs.
dy/dt = f(y,t)

Lecture 2-6

1. The Work of "Physicists" 🍎

Slides 1-3

Solving differential equations is the bread and butter of classical mechanics.

  • Many equations in nature cannot be solved analytically.
  • Numerical approximations are often good enough.
  • Today: Euler, Runge-Kutta, and Animations!
🍏
"Let's get back to F=ma!"

2. Euler's Method

Slide 4-6

Let's solve $\frac{dy}{dt} = y$ with $y(0)=1$. We know the answer is $e^t$.

Algorithm

$$ y_{n+1} \approx y_n + h \cdot f(y_n, t_n) $$

Precision: $O(h)$ (Not very good)

3. The Runge-Kutta Family 🚀

Slides 7-15

RK2 (2nd Order)

Predictor-Corrector approach. Much better than Euler.

RK4 (4th Order)

The standard workhorse. Very precise ($O(h^5)$ local error).

RK45 (Adaptive Step Size)

Automatically adjusts step size $h$ to maintain precision.

4. Physics: The Pendulum 🕰️

Slides 16-25
$$ \frac{d^2\theta}{dt^2} = -\frac{g}{R}\sin(\theta) $$ 1. $\dot{\theta} = \omega$
2. $\dot{\omega} = -\frac{g}{R}\sin(\theta)$

Euler fails to conserve energy. RK4 keeps it stable.

Method: RK4
Energy: 0.00

Animation Code Logic (SciPy Version)

5. Using SciPy `solve_ivp`

Why write your own solver? Use industrial strength tools.

6. Springs & Chaos 🌀

Slides 30+
2D Spring
Energy: 0.00

System Equations

Hooke's Law + Gravity in 2D.

Double Spring (Coupled System)

👐 Hands-On Session

Try simulating these scenarios: