rkc4=function(nt,h,t,y) { # # Function rkc4 implements a second order Runge Kutta method # embedded in a fourth order Runge Kutta method. The ODE routine # has to be renamed for a new application. # # The arguments are # # Input # # nt - number of rkc4 steps between the starting and final # points along the solution # # h - integration step (constant) # # t - initial value of the independent variable # # y - initial dependent variable vector # # Output # # y - solution vector after nt integration steps # # nt rkc4 steps for(i2 in 1:nt){ if(nint==1){ yb=y; tb=t rk1=glucose_2(tb,yb)*h y=yb+0.5*rk1; t=tb+0.5*h rk2=glucose_2(t,y)*h y=yb+0.5*rk2; t=tb+0.5*h rk3=glucose_2(t,y)*h y=yb+rk3; t=tb+h rk4=glucose_2(t,y)*h y=yb+(1/6)*(rk1+2*rk2+2*rk3+rk4) } if(nint==2){ yb=y; tb=t rk1=glucose_2(tb,yb)*h y=yb+0.5*rk1; t=tb+0.5*h rk2=glucose_2(t,y)*h y2=yb+rk2 y=yb+0.5*rk2; t=tb+0.5*h rk3=glucose_2(t,y)*h y=yb+rk3; t=tb+h rk4=glucose_2(t,y)*h y=yb+(1/6)*(rk1+2*rk2+2*rk3+rk4) ee=y-y2 ee <<- ee } } return(c(y)) }