1 /* lmdif1.f -- translated by f2c (version 20020621).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "minpack.h"
7 #include <math.h>
8 #include "minpackP.h"
9
10
11 __minpack_attr__
__minpack_func__(lmdif1)12 void __minpack_func__(lmdif1)(__minpack_decl_fcn_mn__ const int *m, const int *n, real *x,
13 real *fvec, const real *tol, int *info, int *iwa,
14 real *wa, const int *lwa)
15 {
16 /* Initialized data */
17
18 const real factor = 100.;
19
20 int mp5n, mode, nfev;
21 real ftol, gtol, xtol;
22 real epsfcn;
23 int maxfev, nprint;
24
25 /* ********** */
26
27 /* subroutine lmdif1 */
28
29 /* the purpose of lmdif1 is to minimize the sum of the squares of */
30 /* m nonlinear functions in n variables by a modification of the */
31 /* levenberg-marquardt algorithm. this is done by using the more */
32 /* general least-squares solver lmdif. the user must provide a */
33 /* subroutine which calculates the functions. the jacobian is */
34 /* then calculated by a forward-difference approximation. */
35
36 /* the subroutine statement is */
37
38 /* subroutine lmdif1(fcn,m,n,x,fvec,tol,info,iwa,wa,lwa) */
39
40 /* where */
41
42 /* fcn is the name of the user-supplied subroutine which */
43 /* calculates the functions. fcn must be declared */
44 /* in an external statement in the user calling */
45 /* program, and should be written as follows. */
46
47 /* subroutine fcn(m,n,x,fvec,iflag) */
48 /* integer m,n,iflag */
49 /* double precision x(n),fvec(m) */
50 /* ---------- */
51 /* calculate the functions at x and */
52 /* return this vector in fvec. */
53 /* ---------- */
54 /* return */
55 /* end */
56
57 /* the value of iflag should not be changed by fcn unless */
58 /* the user wants to terminate execution of lmdif1. */
59 /* in this case set iflag to a negative integer. */
60
61 /* m is a positive integer input variable set to the number */
62 /* of functions. */
63
64 /* n is a positive integer input variable set to the number */
65 /* of variables. n must not exceed m. */
66
67 /* x is an array of length n. on input x must contain */
68 /* an initial estimate of the solution vector. on output x */
69 /* contains the final estimate of the solution vector. */
70
71 /* fvec is an output array of length m which contains */
72 /* the functions evaluated at the output x. */
73
74 /* tol is a nonnegative input variable. termination occurs */
75 /* when the algorithm estimates either that the relative */
76 /* error in the sum of squares is at most tol or that */
77 /* the relative error between x and the solution is at */
78 /* most tol. */
79
80 /* info is an integer output variable. if the user has */
81 /* terminated execution, info is set to the (negative) */
82 /* value of iflag. see description of fcn. otherwise, */
83 /* info is set as follows. */
84
85 /* info = 0 improper input parameters. */
86
87 /* info = 1 algorithm estimates that the relative error */
88 /* in the sum of squares is at most tol. */
89
90 /* info = 2 algorithm estimates that the relative error */
91 /* between x and the solution is at most tol. */
92
93 /* info = 3 conditions for info = 1 and info = 2 both hold. */
94
95 /* info = 4 fvec is orthogonal to the columns of the */
96 /* jacobian to machine precision. */
97
98 /* info = 5 number of calls to fcn has reached or */
99 /* exceeded 200*(n+1). */
100
101 /* info = 6 tol is too small. no further reduction in */
102 /* the sum of squares is possible. */
103
104 /* info = 7 tol is too small. no further improvement in */
105 /* the approximate solution x is possible. */
106
107 /* iwa is an integer work array of length n. */
108
109 /* wa is a work array of length lwa. */
110
111 /* lwa is a positive integer input variable not less than */
112 /* m*n+5*n+m. */
113
114 /* subprograms called */
115
116 /* user-supplied ...... fcn */
117
118 /* minpack-supplied ... lmdif */
119
120 /* argonne national laboratory. minpack project. march 1980. */
121 /* burton s. garbow, kenneth e. hillstrom, jorge j. more */
122
123 /* ********** */
124 /* Parameter adjustments */
125 --fvec;
126 --iwa;
127 --x;
128 --wa;
129
130 /* Function Body */
131 *info = 0;
132
133 /* check the input parameters for errors. */
134
135 if (*n <= 0 || *m < *n || *tol < 0. || *lwa < *m * *n + *n * 5 + *m) {
136 /* goto L10; */
137 return;
138 }
139
140 /* call lmdif. */
141
142 maxfev = (*n + 1) * 200;
143 ftol = *tol;
144 xtol = *tol;
145 gtol = 0.;
146 epsfcn = 0.;
147 mode = 1;
148 nprint = 0;
149 mp5n = *m + *n * 5;
150 __minpack_func__(lmdif)(__minpack_param_fcn_mn__ m, n, &x[1], &fvec[1], &ftol, &xtol, >ol, &maxfev, &
151 epsfcn, &wa[1], &mode, &factor, &nprint, info, &nfev, &wa[mp5n +
152 1], m, &iwa[1], &wa[*n + 1], &wa[(*n << 1) + 1], &wa[*n * 3 + 1],
153 &wa[(*n << 2) + 1], &wa[*n * 5 + 1]);
154 if (*info == 8) {
155 *info = 4;
156 }
157 /* L10: */
158 return;
159
160 /* last card of subroutine lmdif1. */
161
162 } /* lmdif1_ */
163
164