share/tensor/itensor.lisp: make X and D shared lexical variables for the functions...
[maxima.git] / share / minpack / fortran / hybrd1.f
blobc0a859275d34d151d045f5eba5f739d31e78cb01
1 subroutine hybrd1(fcn,n,x,fvec,tol,info,wa,lwa)
2 integer n,info,lwa
3 double precision tol
4 double precision x(n),fvec(n),wa(lwa)
5 external fcn
6 c **********
8 c subroutine hybrd1
10 c the purpose of hybrd1 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 hybrd. the user
14 c must provide a subroutine which calculates the functions.
15 c the jacobian is then calculated by a forward-difference
16 c approximation.
18 c the subroutine statement is
20 c subroutine hybrd1(fcn,n,x,fvec,tol,info,wa,lwa)
22 c where
24 c fcn is the name of the user-supplied subroutine which
25 c calculates the functions. fcn must be declared
26 c in an external statement in the user calling
27 c program, and should be written as follows.
29 c subroutine fcn(n,x,fvec,iflag)
30 c integer n,iflag
31 c double precision x(n),fvec(n)
32 c ----------
33 c calculate the functions at x and
34 c return this vector in fvec.
35 c ---------
36 c return
37 c end
39 c the value of iflag should not be changed by fcn unless
40 c the user wants to terminate execution of hybrd1.
41 c in this case set iflag to a negative integer.
43 c n is a positive integer input variable set to the number
44 c of functions and variables.
46 c x is an array of length n. on input x must contain
47 c an initial estimate of the solution vector. on output x
48 c contains the final estimate of the solution vector.
50 c fvec is an output array of length n which contains
51 c the functions evaluated at the output x.
53 c tol is a nonnegative input variable. termination occurs
54 c when the algorithm estimates that the relative error
55 c between x and the solution is at most tol.
57 c info is an integer output variable. if the user has
58 c terminated execution, info is set to the (negative)
59 c value of iflag. see description of fcn. otherwise,
60 c info is set as follows.
62 c info = 0 improper input parameters.
64 c info = 1 algorithm estimates that the relative error
65 c between x and the solution is at most tol.
67 c info = 2 number of calls to fcn has reached or exceeded
68 c 200*(n+1).
70 c info = 3 tol is too small. no further improvement in
71 c the approximate solution x is possible.
73 c info = 4 iteration is not making good progress.
75 c wa is a work array of length lwa.
77 c lwa is a positive integer input variable not less than
78 c (n*(3*n+13))/2.
80 c subprograms called
82 c user-supplied ...... fcn
84 c minpack-supplied ... hybrd
86 c argonne national laboratory. minpack project. march 1980.
87 c burton s. garbow, kenneth e. hillstrom, jorge j. more
89 c **********
90 integer index,j,lr,maxfev,ml,mode,mu,nfev,nprint
91 double precision epsfcn,factor,one,xtol,zero
92 data factor,one,zero /1.0d2,1.0d0,0.0d0/
93 info = 0
95 c check the input parameters for errors.
97 if (n .le. 0 .or. tol .lt. zero .or. lwa .lt. (n*(3*n + 13))/2)
98 * go to 20
100 c call hybrd.
102 maxfev = 200*(n + 1)
103 xtol = tol
104 ml = n - 1
105 mu = n - 1
106 epsfcn = zero
107 mode = 2
108 do 10 j = 1, n
109 wa(j) = one
110 10 continue
111 nprint = 0
112 lr = (n*(n + 1))/2
113 index = 6*n + lr
114 call hybrd(fcn,n,x,fvec,xtol,maxfev,ml,mu,epsfcn,wa(1),mode,
115 * factor,nprint,info,nfev,wa(index+1),n,wa(6*n+1),lr,
116 * wa(n+1),wa(2*n+1),wa(3*n+1),wa(4*n+1),wa(5*n+1))
117 if (info .eq. 5) info = 4
118 20 continue
119 return
121 c last card of subroutine hybrd1.