Exercise ODEs
rkstep wich advances
the solution by a step h and estimates the error, e.g.:
function rkstep(f,x,y,h){
// Runge-Kutta midpoint step
var k0 = f(x,y)
var y12 = [y[i]+k0[i]*h/2 for(i in y)]
var k = f(x+h/2,y12)
var y1 = [y[i]+k[i]*h for(i in y)]
var dy = [(k[i]-k0[i])*h/2 for(i in y)]
return [y1, dy]
}
rkstep
with appropriate step-sizes) keeping the specified relative, eps,
and absolute, acc, precision: