program rkdumb_main implicit none integer nstep,NMAX,NSTPMX,n_var,i,j,pgopen parameter (NMAX=50,NSTPMX=200,n_var=2) real xx(NSTPMX),y(NMAX,NSTPMX),x1,x2,vstart(n_var),yy(NSTPMX) real y_min(NMAX), y_max(NMAX) common /path/xx,y external my_derivs write(*,*) 'Type in initial and final values of x :' read(*,*) x1,x2 c Be careful the max value of nstep is 199, not 200, see rkdumb. 100 write(*,*) 'How many steps to integrate the solution ? (<= 199)' read(*,*) nstep if (nstep.gt.199) goto 100 if (nstep.lt.0) goto 100 write(*,*) 'Your problem is an order- ',n_var,' ODE.' do i=1,n_var write(*,*) 'Give the initial value y',i,'(x0) :' read (*,*) vstart(i) end do call rkdumb(vstart,n_var,x1,x2,nstep,my_derivs) write(*,*) 'RK routine has completed.' c Find Max and min values of yi(x), but here we will use only y1(x). do i=1,n_var y_max(i)= y(i,1) y_min(i)= y(i,1) end do do i=1,n_var do j=1,nstep if (y(i,j).gt.y_max(i)) y_max(i)=y(i,j) if (y(i,j).lt.y_min(i)) y_min(i)=y(i,j) end do end do c Copy y(1,1:nstep) to yy(1:nstep) for PGLINE plotting do i=1,nstep yy(i) = y(1,i) end do c Start plotting if (pgopen('/xwin').le.0) stop call pgpap(6.0,0.75) call pgenv (x1,x2,y_min(1),y_max(1),0,0) call pgline(nstep,xx,yy) call pgclos end subroutine my_derivs(x,y,dydx) real x,y(2),dydx(2) dydx(1) = y(2) dydx(2) = -y(1) end