Not all ODE’s can be solved analytically, approximate solutions can always be found numerically
💼 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
Setup:
Algorithm:
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} $$
💼 Case: Consider the exact solution $x(t_{n+1})=x(t_n+h)$ of $\dot x(t)=f(x,t)$
If we expand in $h$:
$$ \begin{aligned} x(t_n + h) &= x(t_n) + h\dot x(t_n)+\frac{1}{2} h^2 \ddot x(t_n)+\mathcal O (h^3) \\ {\color{lime} x(t_n+h)}&={\color{cyan}x(t_n) + h\dot x(t_n)}+{\color{orange}\mathcal O (h^2)} \end{aligned} $$
Green is the exact solution, blue is the Euler expression and yellow is all the extra terms missing from Euler
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} $$
Solve $\dot x=x^2$ with $x(0)=0.1$ using Euler’s method
The exact solution
$$
\int ^{x(t)}_{x_0}\frac{\text dx}{x^2}=\int_0^t \text dt \\ x(t)=\frac{1}{10-t} $$
$$ \dot x(t+ \frac{h}{2})\simeq \frac{x(t+h)-x(t)}{h} $$