Program c05ndfe ! C05NDF Example Program Text ! Mark 24 Release. NAG Copyright 2012. ! .. Use Statements .. Use nag_library, Only: c05ndf, dnrm2, nag_wp, x02ajf ! .. Implicit None Statement .. Implicit None ! .. Parameters .. Integer, Parameter :: n = 9, nout = 6 Integer, Parameter :: ldfjac = n ! .. Local Scalars .. Real (Kind=nag_wp) :: epsfcn, factor, fnorm, xtol Integer :: icount, ifail, irevcm, j, lr, ml, & mode, mu ! .. Local Arrays .. Real (Kind=nag_wp), Allocatable :: diag(:), fjac(:,:), fvec(:), qtf(:), & r(:), w(:,:), x(:) ! .. Intrinsic Procedures .. Intrinsic :: sqrt ! .. Executable Statements .. Write (nout,*) 'C05NDF Example Program Results' Allocate (diag(n),fjac(ldfjac,n),fvec(n),qtf(n),r(n*(n+ & 1)/2),w(n,4),x(n)) ! The following starting values provide a rough solution. x(1:n) = -1.0E0_nag_wp xtol = sqrt(x02ajf()) diag(1:n) = 1.0E0_nag_wp ml = 1 mu = 1 epsfcn = 0.0E0_nag_wp mode = 2 factor = 100.0E0_nag_wp icount = 0 irevcm = 0 ifail = -1 revcomm: Do Call c05ndf(irevcm,n,x,fvec,xtol,ml,mu,epsfcn,diag,mode,factor,fjac, & ldfjac,r,lr,qtf,w,ifail) Select Case (irevcm) Case (1) icount = icount + 1 ! Insert print statements here to monitor progess if desired. Cycle revcomm Case (2) ! Evaluate functions at given point fvec(1:n) = (3.0E0_nag_wp-2.0E0_nag_wp*x(1:n))*x(1:n) + 1.0E0_nag_wp fvec(2:n) = fvec(2:n) - x(1:(n-1)) fvec(1:(n-1)) = fvec(1:(n-1)) - 2.0E0_nag_wp*x(2:n) Cycle revcomm Case Default Exit revcomm End Select End Do revcomm Write (nout,*) Select Case (ifail) Case (0) ! The NAG name equivalent of dnrm2 is f06ejf fnorm = dnrm2(n,fvec,1) Write (nout,99999) 'Final 2-norm of the residuals after', icount, & ' iterations is ', fnorm Write (nout,*) Write (nout,*) 'Final approximate solution' Write (nout,99998)(x(j),j=1,n) Case (3:) Write (nout,*) 'Approximate solution' Write (nout,99998)(x(j),j=1,n) End Select 99999 Format (1X,A,I4,A,E12.4) 99998 Format (5X,3F12.4) End Program c05ndfe