program mnewt_main implicit none c integer n_max to define maximum n integer n_max, i, i_again parameter (n_max = 16) c integer for mnewt, n has to be smaller than NP=16 integer ntrial,n parameter (n=2) real x(n),tolx,tolf write(*,*) 'How many repeating steps for Newton methods ?' read(*,*) ntrial c write(*,*) 'How many variables is there in your problem ?' c read(*,*) n write(*,*) 'Please type in x tol and f tol for mnewt :' read(*,*) tolx, tolf 100 write(*,*) 'What is your inital guess on x(i) vector ?' read(*,*) (x(i),i=1,n) call mnewt(ntrial,x,n,tolx,tolf) write(*,*) 'The root vector is :' do i=1,n write(*,*) x(i) end do 101 write(*,*) 'Find root again ? (1=Yes;0=No)' read(*,*) i_again if (i_again.eq.1) goto 100 if (i_again.eq.0) stop goto 101 end subroutine usrfun (x,n,NP,fvec,fjac) integer n,NP real x(n),fvec(NP),fjac(NP,NP) c fvec(1) = x(1)**2 + x(2)**2 - 25 c fvec(2) = x(2) c fjac(1,1) = 2*x(1) c fjac(2,1) = 0 c fjac(1,2) = 2*x(2) c fjac(2,2) = 1 c fvec(1) = x(1)**2 - x(2) - 1 c fvec(2) = x(2) c fjac(1,1) = 2*x(1) c fjac(2,1) = 0 c fjac(1,2) = -1 c fjac(2,2) = 1 c fvec(1) = x(2) - x(1) c fvec(2) = x(2) + x(1) c fjac(1,1) = -1 c fjac(2,1) = 1 c fjac(1,2) = 1 c fjac(2,2) = 1 c fvec(1) = x(2) c fvec(2) = x(1) c fjac(1,1) = 0 c fjac(2,1) = 1 c fjac(1,2) = 1 c fjac(2,2) = 0 c fvec(1) = x(1)**2 - 4*x(1) + 4 + x(2)**2 - 25 c fvec(2) = x(1)**2 + 4*x(1) + 4 + x(2)**2 - 25 c fjac(1,1) = 2*x(1) - 4 c fjac(2,1) = 2*x(1) + 4 c fjac(1,2) = 2*x(2) c fjac(2,2) = 2*x(2) fvec(1) = x(1)**2 - 4*x(1) + 4 + x(2)**2 - 25 fvec(2) = x(2) fjac(1,1) = 2*x(1) - 4 fjac(2,1) = 0 fjac(1,2) = 2*x(2) fjac(2,2) = 1 end