# -*- coding: utf-8 -*- """ You can use this function in your program to take one Runge-Kutta step I wrote this mainly so you can correct errors in your own code, not to just copy Note that the function creates 5 temporary variables, dt2,vs, vs2, vs3 and vnext. Plus, this is written to allow the use of the independent variable (t) although it is not used in our application Created on Thu Feb 8 12:28:50 2021 @author: neil """ def RungeKutta(f,v,t,delt): """ Calculate one Runge Kutta step, input is the (your) derivative function (f), current value of depenent variable (v), current value independent variable (t), and size of step. Output is value of the independent variable at t plus delt """ dt2 = delt/2 # create 4 temp vars, this is a 1/2 step in t vs = v + dt2*f(v,t) # the vs temps are for the final calculation vs2 = v + dt2*f(vs, t + dt2) # of the R-K step vs3 = v + delt*f(vs2,t + dt2) vnext = v + delt*(f(v,t)/6 + f(vs,t+dt2)/3 + f(vs2,t+dt2)/3 + f(vs3,t+delt)/6) return vnext # return the fourth order R-K step