There are three broad sets of problems involving ODEs.
Implement Euler method using the skeleton in the cell below.
import numpy as np
from matplotlib import pyplot as plt
def ode_euler(func, x0, t0, tn, dt=0.2) :
return xt
Test your code on the following problem: Find $x(1)$ for
$$
\frac{dx}{dt} = x
$$
with $x(t_0) = 1$ at $t_0 = 0$. Try it initially with $dt = 0.2$. Later, reduce
### Try your code here on the test problem given
Again, the trick is to
Implement the Runge-Kutta order 1 method in the cell below.
def ode_rk1(func, x0, t0, tn, dt=0.2) :
return xtn
Do the same problem as above with the Euler method to verify your code. You will find that the method gives you a much better approximation to $e$.
def func(x, t) :
return x
xinit = 1.0
tinit = 0.0
delta = 0.2
tfinal = 1.0
x1 = ode_euler(func, xinit, tinit, tfinal, dt=delta)
print(x1)
xrk = ode_rk1(func, xinit, tinit, tfinal, dt=delta)
print(xrk)