[ Home ] | Numerical Methods. Note « 9 » |
subroutine dydx(n,x,y,f); dimension y(n),f(n)
f(1)= ... ; f(2)=...; ...; f(n)=...; return; end
where the column of the right-hand-sides is returned in an array f
.
Midpoint Runge-Kutta method for system of differential equations. For simplicity we shall only implement the midpoint method for systems of equations:
k0 = f(x,y0) , k1/2 = f(x+h/2,y0 + h/2k0) , y1 = y0 + hk1/2 , err = h|k0-k1/2|/2
Finite difference methods.
subroutine rk(a,b,f,n,nmax,y0,x,y,k,kmax,h,eps,acc,gerr,ak0,ak12) dimension x(kmax),y(nmax,kmax),y0(nmax),ak0(nmax),ak12(nmax); external fwhere y(i,j)=yi(xj) is the solution, ak0 and ak12 is the storage for k0 and k1/2, gerr is the estimated global error and h is the initial step.
The driver calls the stepper -- the subroutine that performs the very Runge-Kutta step:
subroutine rkstep(n,x,y0,y1,f,h,err,ak0,ak12) dimension y0(n),y1(n),ak0(n),ak12(n)