Runge-Kutta 4 steps

You will find this code in the EJS console at page Initialization

lines marked //  include remarks that do not influence the calculation.

xRK[0]=0;

yRK[0]=valueFrom;

derivativeRK[0]=yRK[0];//for exponential

for (var i=1; i<n; i++) { //loop definition)

y_a[i]=yRK[i-1]+delta/2*derivativeRK[i-1];

derivative_a[i]=y_a[i];//for exponential

y_b[i]=yRK[i-1]+delta/2*derivative_a[i];

derivative_b[i]=y_b[i];//for exponential

y_c[i]=yRK[i-1]+delta*derivative_b[i];

derivative_c[i]=y_c[i];//for exponential

yRK[i]=yRK[i-1]+delta/6*(derivativeRK[i-1]+2*derivative_a[i]+2*derivative_b[i]+derivative_c[i]);

xRK[i]=xRK[i-1]+delta;

derivativeRK[i]=yRK[i];//for exponential

FRK[i]=(valueFrom*Math.exp(xRK[i])-yRK[i])/(valueFrom*Math.exp(xRK[i]));

//back to start of loop

}