implicit none integer i,n real a,b,h,x,y,xl,yl,f,g real yp,k1,y0,z0 real l1,zl,z,zp real err,exact character char*11 print*,' Enter number of intervals n' read(5,*) n print*,' Enter a,b,y(a),dydx(a)' read(5,*) a,b,y0,z0 h=(b-a)/float(n) 100 continue y=y0 z=z0 x=a write(6,30) x,y,z 30 format(/,' Solving with 4th Runge-Kutta gives:',/, & ' X Y dY/dX exact %error', & /,1x,f5.3,1x,f10.6,1x,f10.6) do i=1,n xl=x yl=y zl=z k1=h*f(xl,yl,zl) l1=h*g(xl,yl,zl) x=xl+h y=yl+k1 z=zl+l1 exact=sin(x) if(abs(exact).gt.1.e-6) then err=100.0*(y-exact)/exact write(6,2) x,y,z,exact,err else char='div by zero' write(6,3) x,y,z,exact,char endif enddo 2 format(1x,f6.3,1x,f10.6,1x,f10.6,1x,f10.6,1x,f10.6) 3 format(1x,f6.3,1x,f10.6,1x,f10.6,1x,f10.6,2x,a11) stop end real function f(x,y,z) implicit none real x,y,z f=z return end real function g(x,y,z) implicit none real x,y,z g=-y return end