PROGRAM example20 ! Runge-Kutta method ! will only do first half of question IMPLICIT NONE REAL :: x,y,h,k1,k2,k3,k4,error REAL :: x1,y1,xmax INTEGER :: I,J,jval,jprint INTERFACE FUNCTION func(x,y) IMPLICIT NONE REAL, INTENT(IN) :: x,y REAL :: func END FUNCTION func FUNCTION sol(x) IMPLICIT NONE REAL :: sol REAL , INTENT(IN):: x END FUNCTION sol END INTERFACE PRINT *, 'enter step size and maximum x value' READ *, h,xmax x=0 y=1 error=y-sol(x) WRITE(6,1000)x,y,error 1000 FORMAT(5(E12.5,1X)) jval=1 ! the jval count when we get to integer values of x ! jprint is how many h steps to reach x=1 jprint=NINT(1./h) DO WHILE (x <= xmax) k1=func(x,y) x1=x+h*.5 y1=y+h*k1*.5 k2=func(x1,y1) y1=y+h*k2*0.5 k3=func(x1,y1) x1=x+h y1=y+h*k3 k4=func(x1,y1) y=y+(h/6.)*(k1+2.*k2+2.*k3+k4) x=x1 error= y-sol(x) ! check if x is close to integer value for printing if(jval==jprint)THEN WRITE(6,1000)x,y,error ! now reset counter jval jval=0 ENDIF jval=jval+1 ENDDO END PROGRAM example20 FUNCTION func(x,y) IMPLICIT NONE REAL, INTENT(IN) :: x,y REAL :: func func = y*0.25*(1.-(y/20.)) END FUNCTION func FUNCTION sol(x) IMPLICIT NONE REAL :: sol REAL , INTENT(IN):: x sol=20./(1.+ 19.*EXP(-x*.25)) END FUNCTION sol