from numpy import array, dot import math import matplotlib.pyplot as plt def euler_step(f, h, x, y, threshold = 0): return x+h, y + h*f(x, y),h def r_k_step(f, h, x, y,threshold = 0): k1 = h * f(x, y) k2 = h*f(x + h/2, y + k1/2) k3 = h*f(x + h/2, y + k2/2) k4 = h * f(x + h, y + k3) return x+h, y + k1/6 + k2/3 + k3/3 + k4/6, h def r_k_adaptive_step(f, h, x, y, threshold): #do step, half and double y_step = r_k_step(f, h, x, y)[1] y_half_step = r_k_step(f, h/2, x, y)[1] y_two_half_step = r_k_step(f, h/2, x + h/2, y_half_step)[1] #if step is good enough, (step-half)