1 subroutine hybrj1(fcn,n,x,fvec,fjac,ldfjac,tol,info,wa,lwa) 2 integer n,ldfjac,info,lwa 3 double precision tol 4 double precision x(n),fvec(n),fjac(ldfjac,n),wa(lwa) 5 external fcn 6c ********** 7c 8c subroutine hybrj1 9c 10c the purpose of hybrj1 is to find a zero of a system of 11c n nonlinear functions in n variables by a modification 12c of the powell hybrid method. this is done by using the 13c more general nonlinear equation solver hybrj. the user 14c must provide a subroutine which calculates the functions 15c and the jacobian. 16c 17c the subroutine statement is 18c 19c subroutine hybrj1(fcn,n,x,fvec,fjac,ldfjac,tol,info,wa,lwa) 20c 21c where 22c 23c fcn is the name of the user-supplied subroutine which 24c calculates the functions and the jacobian. fcn must 25c be declared in an external statement in the user 26c calling program, and should be written as follows. 27c 28c subroutine fcn(n,x,fvec,fjac,ldfjac,iflag) 29c integer n,ldfjac,iflag 30c double precision x(n),fvec(n),fjac(ldfjac,n) 31c ---------- 32c if iflag = 1 calculate the functions at x and 33c return this vector in fvec. do not alter fjac. 34c if iflag = 2 calculate the jacobian at x and 35c return this matrix in fjac. do not alter fvec. 36c --------- 37c return 38c end 39c 40c the value of iflag should not be changed by fcn unless 41c the user wants to terminate execution of hybrj1. 42c in this case set iflag to a negative integer. 43c 44c n is a positive integer input variable set to the number 45c of functions and variables. 46c 47c x is an array of length n. on input x must contain 48c an initial estimate of the solution vector. on output x 49c contains the final estimate of the solution vector. 50c 51c fvec is an output array of length n which contains 52c the functions evaluated at the output x. 53c 54c fjac is an output n by n array which contains the 55c orthogonal matrix q produced by the qr factorization 56c of the final approximate jacobian. 57c 58c ldfjac is a positive integer input variable not less than n 59c which specifies the leading dimension of the array fjac. 60c 61c tol is a nonnegative input variable. termination occurs 62c when the algorithm estimates that the relative error 63c between x and the solution is at most tol. 64c 65c info is an integer output variable. if the user has 66c terminated execution, info is set to the (negative) 67c value of iflag. see description of fcn. otherwise, 68c info is set as follows. 69c 70c info = 0 improper input parameters. 71c 72c info = 1 algorithm estimates that the relative error 73c between x and the solution is at most tol. 74c 75c info = 2 number of calls to fcn with iflag = 1 has 76c reached 100*(n+1). 77c 78c info = 3 tol is too small. no further improvement in 79c the approximate solution x is possible. 80c 81c info = 4 iteration is not making good progress. 82c 83c wa is a work array of length lwa. 84c 85c lwa is a positive integer input variable not less than 86c (n*(n+13))/2. 87c 88c subprograms called 89c 90c user-supplied ...... fcn 91c 92c minpack-supplied ... hybrj 93c 94c argonne national laboratory. minpack project. march 1980. 95c burton s. garbow, kenneth e. hillstrom, jorge j. more 96c 97c ********** 98 integer j,lr,maxfev,mode,nfev,njev,nprint 99 double precision factor,one,xtol,zero 100 data factor,one,zero /1.0d2,1.0d0,0.0d0/ 101 info = 0 102c 103c check the input parameters for errors. 104c 105 if (n .le. 0 .or. ldfjac .lt. n .or. tol .lt. zero 106 * .or. lwa .lt. (n*(n + 13))/2) go to 20 107c 108c call hybrj. 109c 110 maxfev = 100*(n + 1) 111 xtol = tol 112 mode = 2 113 do 10 j = 1, n 114 wa(j) = one 115 10 continue 116 nprint = 0 117 lr = (n*(n + 1))/2 118 call hybrj(fcn,n,x,fvec,fjac,ldfjac,xtol,maxfev,wa(1),mode, 119 * factor,nprint,info,nfev,njev,wa(6*n+1),lr,wa(n+1), 120 * wa(2*n+1),wa(3*n+1),wa(4*n+1),wa(5*n+1)) 121 if (info .eq. 5) info = 4 122 20 continue 123 return 124c 125c last card of subroutine hybrj1. 126c 127 end 128