[ Home ] Numerical Methods. Note « 9 »

NB:
Send me an email when you are done with a given obligatory exercise. Check that there's the source code, an informative output, and a graph (when needed).
Lectures

Integration of systems of differential equations

We shall discuss here the generalization of the Runge-Kutta methods for a system of differential equations y'(x) = f(x,y), where y = {y1,y2,...,yn} is a column of unknown functions and f = {f1,f2,...,fn} is a column of the right-hand-sides. The initial condition is now also a column y(x0) = y0. The user-supplied subroutine to calculate the right-hand-sides should be modified like, for example
 
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.

Problems
  1. Generalize your Runge-Kutta routine to system of differential equations (use midpoint method for simpicity). Your step-size controlling (driver) subroutine may have the following prototype
    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 f
    
    where 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)
    
  2. Integrate the equation y''(x)=-y , y(0)=0 , y'(0)=1 from a=0 to b=4π.

"Copyleft" © 2001 D.V.Fedorov (fedorov@ifa.au.dk)