Runge Kutta’s (4th Order) Method Fortran

Fortran Programming - Bottom Science

Runge Kutta’s (4th Order) Method Fortran

Fortran Code

PROGRAM runge_fourth
IMPLICIT NONE

REAL::x0=1,y0=2.3,x,x1,y1,k1,k2,k3,k4,k,f,h
x1=x0
y1=y0

PRINT *,'====================================================' 
PRINT *,"Program for Runge Kutta’s 4th order method [www.BottomScience.com]" 
PRINT *,'===================================================='

PRINT *,'Step size (h)?'
READ(*,*)h

PRINT *,'value?'
READ(*,*)x

PRINT *,x1,y1

DO WHILE (x1<x)

  k1=h*f(x1,y1)
  k2=h*f(x1+(h/2),y1+(k1/2))
  k3=h*f(x1+(h/2),y1+(k2/2))
  k4=h*f(x1+h,y1+k3)

  k=(1/6.)*(k1+(2*k2)+(2*k3)+k4)

  y1=y1+k

  PRINT *,x1+h,y1

  x1=x1+h

END DO

END PROGRAM

REAL function f(x1,y1)
REAL::x1,y1
  f=(x1**2)+(y1**2)
return
end function

See Also | More Fortran Programs

References:

  1. Derivation of the Runge–Kutta fourth-order method

 

Leave a Reply

Your email address will not be published.