math - what will be python code for runge kutta second method? -
is code ok? def rkn(x, fx, n, hs): k1 = [] k2 = [] k3 = [] k4 = [] xk = [] in range(n): k1.append(fx[i](x)*hs) in range(n): xk.append(x[i] + k1[i]*0.5) in range(n): k2.append(fx[i](xk)*hs) in range(n): xk[i] = x[i] + k2[i]*0.5 in range(n): k3.append(fx[i](xk)*hs) in range(n): xk[i] = x[i] + k3[i] in range(n): k4.append(fx[i](xk)*hs) in range(n): x[i] = x[i] + (k1[i] + 2*(k2[i] + k3[i]) + k4[i])/6 return x with numpy seems more readable: code taken http://www.math-cs.gordon.edu/courses/mat342/python/diffeq.py def rk2a( f, x0, t ): """second-order runge-kutta method solve x' = f(x,t) x(t[0]) = x0. usage: x = rk2a(f, x0, t) input: f - function of x , t equal dx/dt. x may multivalued, in case should list or numpy array. in case f must return numpy array same dimensio...