Runge Kutta’s (2nd Order) Method | FORTRAN 95

Fortran Programming - Bottom Science

Fortran Code

PROGRAM runge_second
IMPLICIT NONE
REAL::x0=1,y0=2.3,x,x1,y1,k1,k2,f,h

x1=x0
y1=y0

PRINT *,'====================================================' 
PRINT *,"Program for Runge Kutta’s 2nd 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,y1+k1)

  y1=y1+(0.5*(k1+k2))

  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

Leave a Reply

Your email address will not be published.