1 subroutine lmdif1
(fcn
,m
,n
,x
,fvec
,tol
,info
,iwa
,wa
,lwa
)
5 double precision x
(n
),fvec
(m
),wa
(lwa
)
11 c the purpose of lmdif1 is to minimize the sum of the squares of
12 c m nonlinear functions in n variables by a modification of the
13 c levenberg-marquardt algorithm. this is done by using the more
14 c general least-squares solver lmdif. the user must provide a
15 c subroutine which calculates the functions. the jacobian is
16 c then calculated by a forward-difference approximation.
18 c the subroutine statement is
20 c subroutine lmdif1(fcn,m,n,x,fvec,tol,info,iwa,wa,lwa)
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(m,n,x,fvec,iflag)
31 c double precision x(n),fvec(m)
33 c calculate the functions at x and
34 c return this vector in fvec.
39 c the value of iflag should not be changed by fcn unless
40 c the user wants to terminate execution of lmdif1.
41 c in this case set iflag to a negative integer.
43 c m is a positive integer input variable set to the number
46 c n is a positive integer input variable set to the number
47 c of variables. n must not exceed m.
49 c x is an array of length n. on input x must contain
50 c an initial estimate of the solution vector. on output x
51 c contains the final estimate of the solution vector.
53 c fvec is an output array of length m which contains
54 c the functions evaluated at the output x.
56 c tol is a nonnegative input variable. termination occurs
57 c when the algorithm estimates either that the relative
58 c error in the sum of squares is at most tol or that
59 c the relative error between x and the solution is at
62 c info is an integer output variable. if the user has
63 c terminated execution, info is set to the (negative)
64 c value of iflag. see description of fcn. otherwise,
65 c info is set as follows.
67 c info = 0 improper input parameters.
69 c info = 1 algorithm estimates that the relative error
70 c in the sum of squares is at most tol.
72 c info = 2 algorithm estimates that the relative error
73 c between x and the solution is at most tol.
75 c info = 3 conditions for info = 1 and info = 2 both hold.
77 c info = 4 fvec is orthogonal to the columns of the
78 c jacobian to machine precision.
80 c info = 5 number of calls to fcn has reached or
83 c info = 6 tol is too small. no further reduction in
84 c the sum of squares is possible.
86 c info = 7 tol is too small. no further improvement in
87 c the approximate solution x is possible.
89 c iwa is an integer work array of length n.
91 c wa is a work array of length lwa.
93 c lwa is a positive integer input variable not less than
98 c user-supplied ...... fcn
100 c minpack-supplied ... lmdif
102 c argonne national laboratory. minpack project. march 1980.
103 c burton s. garbow, kenneth e. hillstrom, jorge j. more
106 integer maxfev
,mode
,mp5n
,nfev
,nprint
107 double precision epsfcn
,factor
,ftol
,gtol
,xtol
,zero
108 data factor
,zero
/1.0d2
,0.0d0
/
111 c check the input parameters for errors.
113 if (n
.le
. 0 .or
. m
.lt
. n
.or
. tol
.lt
. zero
114 * .or
. lwa
.lt
. m*n
+ 5*n
+ m
) go to 10
126 call lmdif
(fcn
,m
,n
,x
,fvec
,ftol
,xtol
,gtol
,maxfev
,epsfcn
,wa
(1),
127 * mode
,factor
,nprint
,info
,nfev
,wa
(mp5n
+1),m
,iwa
,
128 * wa
(n
+1),wa
(2*n
+1),wa
(3*n
+1),wa
(4*n
+1),wa
(5*n
+1))
129 if (info
.eq
. 8) info
= 4
133 c last card of subroutine lmdif1.