maths.numerical_analysis.runge_kutta¶
Functions¶
|
Calculate the numeric solution at each step to the ODE f(x, y) using RK4 |
Module Contents¶
- maths.numerical_analysis.runge_kutta.runge_kutta(f, y0, x0, h, x_end)¶
Calculate the numeric solution at each step to the ODE f(x, y) using RK4
https://en.wikipedia.org/wiki/Runge-Kutta_methods
Arguments: f – The ode as a function of x and y y0 – the initial value for y x0 – the initial value for x h – the stepsize x_end – the end value for x
>>> # the exact solution is math.exp(x) >>> def f(x, y): ... return y >>> y0 = 1 >>> y = runge_kutta(f, y0, 0.0, 0.01, 5) >>> float(y[-1]) 148.41315904125113