share/tensor/itensor.lisp: make X and D shared lexical variables for the functions...
[maxima.git] / share / minpack / fortran / hybrj1.f
blob9f51c496572fbc16596717beae64ddcfff03f83e
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
6 c **********
8 c subroutine hybrj1
10 c the purpose of hybrj1 is to find a zero of a system of
11 c n nonlinear functions in n variables by a modification
12 c of the powell hybrid method. this is done by using the
13 c more general nonlinear equation solver hybrj. the user
14 c must provide a subroutine which calculates the functions
15 c and the jacobian.
17 c the subroutine statement is
19 c subroutine hybrj1(fcn,n,x,fvec,fjac,ldfjac,tol,info,wa,lwa)
21 c where
23 c fcn is the name of the user-supplied subroutine which
24 c calculates the functions and the jacobian. fcn must
25 c be declared in an external statement in the user
26 c calling program, and should be written as follows.
28 c subroutine fcn(n,x,fvec,fjac,ldfjac,iflag)
29 c integer n,ldfjac,iflag
30 c double precision x(n),fvec(n),fjac(ldfjac,n)
31 c ----------
32 c if iflag = 1 calculate the functions at x and
33 c return this vector in fvec. do not alter fjac.
34 c if iflag = 2 calculate the jacobian at x and
35 c return this matrix in fjac. do not alter fvec.
36 c ---------
37 c return
38 c end
40 c the value of iflag should not be changed by fcn unless
41 c the user wants to terminate execution of hybrj1.
42 c in this case set iflag to a negative integer.
44 c n is a positive integer input variable set to the number
45 c of functions and variables.
47 c x is an array of length n. on input x must contain
48 c an initial estimate of the solution vector. on output x
49 c contains the final estimate of the solution vector.
51 c fvec is an output array of length n which contains
52 c the functions evaluated at the output x.
54 c fjac is an output n by n array which contains the
55 c orthogonal matrix q produced by the qr factorization
56 c of the final approximate jacobian.
58 c ldfjac is a positive integer input variable not less than n
59 c which specifies the leading dimension of the array fjac.
61 c tol is a nonnegative input variable. termination occurs
62 c when the algorithm estimates that the relative error
63 c between x and the solution is at most tol.
65 c info is an integer output variable. if the user has
66 c terminated execution, info is set to the (negative)
67 c value of iflag. see description of fcn. otherwise,
68 c info is set as follows.
70 c info = 0 improper input parameters.
72 c info = 1 algorithm estimates that the relative error
73 c between x and the solution is at most tol.
75 c info = 2 number of calls to fcn with iflag = 1 has
76 c reached 100*(n+1).
78 c info = 3 tol is too small. no further improvement in
79 c the approximate solution x is possible.
81 c info = 4 iteration is not making good progress.
83 c wa is a work array of length lwa.
85 c lwa is a positive integer input variable not less than
86 c (n*(n+13))/2.
88 c subprograms called
90 c user-supplied ...... fcn
92 c minpack-supplied ... hybrj
94 c argonne national laboratory. minpack project. march 1980.
95 c burton s. garbow, kenneth e. hillstrom, jorge j. more
97 c **********
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
103 c check the input parameters for errors.
105 if (n .le. 0 .or. ldfjac .lt. n .or. tol .lt. zero
106 * .or. lwa .lt. (n*(n + 13))/2) go to 20
108 c call hybrj.
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
125 c last card of subroutine hybrj1.