Euler’s Modified Method | FORTRAN 95

Fortran Programming - Bottom Science

Fortran Code

PROGRAM euler_modified_method
IMPLICIT NONE

REAL::x0=0,y0=-1,x,x1,f,h,y1,y2
x1=x0
y1=y0

PRINT *,'====================================================' 
PRINT *,"Program for Euler’s modified method [www.BottomScience.com]" 
PRINT *,'===================================================='

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

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

PRINT *,x1,y1

DO WHILE (x1<x)
  y2=y1+(h*f(x1,y1))
  !Modification
  y2=y1+(0.5*h)*(f(x1,y1)+f(x1+h,y2))
  PRINT *,x1+h,y2
  x1=x1+h
  y1=y2
END DO

END PROGRAM

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

Leave a Reply

Your email address will not be published.