Not all ODE’s can be solved analytically, approximate solutions can always be found numerically

Euler method

💼 Case: finding $x(t_f)$ given $\dot x= f(x,t)$ and initial condition $x(t=t_0)=x_0$

🗒️ Note: Using numerical methods we can only have discrete times and not continuous

🧭 Algorithm

Setup:

Algorithm:

Screenshot 2024-10-07 190231.png

  1. Start at $x_n$
  2. Find slope at $f(x_n,t_n)$
  3. move by slope $\times h$

Or mathematically

$$ \begin{aligned} \dot x(t)&\simeq \frac{x(t+h)-x(t)}{h} \\\text{so:} \;x_{n+1}&=x_n + hf(x_n,t_n) \end{aligned} $$

🎮 Accuracy

💼 Case: Consider the exact solution $x(t_{n+1})=x(t_n+h)$ of $\dot x(t)=f(x,t)$

image.png

Going from $t_0$ to $t_f$

$$ \begin{aligned} \text{number of steps}&\times\text{Error at each step} \\ ~\mathcal O (h^{-1})&\times O(h^2) \\ ~ \mathcal O&(h) \end{aligned} $$

💃 Example

Solve $\dot x=x^2$ with $x(0)=0.1$ using Euler’s method

image.png

Midpoint method

$$ \dot x(t+ \frac{h}{2})\simeq \frac{x(t+h)-x(t)}{h} $$