share/tensor/itensor.lisp: make X and D shared lexical variables for the functions...
[maxima.git] / share / minpack / lisp / lmdif.lisp
blobfa77edfa0830fb8bff2802220557c29f7e6828ae
1 ;;; Compiled by f2cl version:
2 ;;; ("f2cl1.l,v 1.215 2009/04/07 22:05:21 rtoy Exp $"
3 ;;; "f2cl2.l,v 1.37 2008/02/22 22:19:33 rtoy Exp $"
4 ;;; "f2cl3.l,v 1.6 2008/02/22 22:19:33 rtoy Exp $"
5 ;;; "f2cl4.l,v 1.7 2008/02/22 22:19:34 rtoy Exp $"
6 ;;; "f2cl5.l,v 1.200 2009/01/19 02:38:17 rtoy Exp $"
7 ;;; "f2cl6.l,v 1.48 2008/08/24 00:56:27 rtoy Exp $"
8 ;;; "macros.l,v 1.112 2009/01/08 12:57:19 rtoy Exp $")
10 ;;; Using Lisp CMU Common Lisp 19f (19F)
11 ;;;
12 ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls nil)
13 ;;; (:coerce-assigns :as-needed) (:array-type ':array)
14 ;;; (:array-slicing t) (:declare-common nil)
15 ;;; (:float-format double-float))
17 (in-package :minpack)
20 (let ((one 1.0)
21 (p1 0.1)
22 (p5 0.5)
23 (p25 0.25)
24 (p75 0.75)
25 (p0001 1.0e-4)
26 (zero 0.0))
27 (declare (type (double-float) one p1 p5 p25 p75 p0001 zero))
28 (defun lmdif
29 (fcn m n x fvec ftol xtol gtol maxfev epsfcn diag mode factor nprint
30 info nfev fjac ldfjac ipvt qtf wa1 wa2 wa3 wa4)
31 (declare (type (array f2cl-lib:integer4 (*)) ipvt)
32 (type (double-float) factor epsfcn gtol xtol ftol)
33 (type (array double-float (*)) wa4 wa3 wa2 wa1 qtf fjac diag fvec
35 (type (f2cl-lib:integer4) ldfjac nfev info nprint mode maxfev n
36 m))
37 (f2cl-lib:with-multi-array-data
38 ((x double-float x-%data% x-%offset%)
39 (fvec double-float fvec-%data% fvec-%offset%)
40 (diag double-float diag-%data% diag-%offset%)
41 (fjac double-float fjac-%data% fjac-%offset%)
42 (qtf double-float qtf-%data% qtf-%offset%)
43 (wa1 double-float wa1-%data% wa1-%offset%)
44 (wa2 double-float wa2-%data% wa2-%offset%)
45 (wa3 double-float wa3-%data% wa3-%offset%)
46 (wa4 double-float wa4-%data% wa4-%offset%)
47 (ipvt f2cl-lib:integer4 ipvt-%data% ipvt-%offset%))
48 (prog ((actred 0.0) (delta 0.0) (dirder 0.0) (epsmch 0.0) (fnorm 0.0)
49 (fnorm1 0.0) (gnorm 0.0) (par 0.0) (pnorm 0.0) (prered 0.0)
50 (ratio 0.0) (sum 0.0) (temp 0.0) (temp1 0.0) (temp2 0.0)
51 (xnorm 0.0) (i 0) (iflag 0) (iter 0) (j 0) (l 0))
52 (declare (type (f2cl-lib:integer4) l j iter iflag i)
53 (type (double-float) xnorm temp2 temp1 temp sum ratio prered
54 pnorm par gnorm fnorm1 fnorm epsmch
55 dirder delta actred))
56 '" **********"
57 '""
58 '" subroutine lmdif"
59 '""
60 '" the purpose of lmdif is to minimize the sum of the squares of"
61 '" m nonlinear functions in n variables by a modification of"
62 '" the levenberg-marquardt algorithm. the user must provide a"
63 '" subroutine which calculates the functions. the jacobian is"
64 '" then calculated by a forward-difference approximation."
65 '""
66 '" the subroutine statement is"
67 '""
68 '" subroutine lmdif(fcn,m,n,x,fvec,ftol,xtol,gtol,maxfev,epsfcn,"
69 '" diag,mode,factor,nprint,info,nfev,fjac,"
70 '" ldfjac,ipvt,qtf,wa1,wa2,wa3,wa4)"
71 '""
72 '" where"
73 '""
74 '" fcn is the name of the user-supplied subroutine which"
75 '" calculates the functions. fcn must be declared"
76 '" in an external statement in the user calling"
77 '" program, and should be written as follows."
78 '""
79 '" subroutine fcn(m,n,x,fvec,iflag)"
80 '" integer m,n,iflag"
81 '" double precision x(n),fvec(m)"
82 '" ----------"
83 '" calculate the functions at x and"
84 '" return this vector in fvec."
85 '" ----------"
86 '" return"
87 '" end"
88 '""
89 '" the value of iflag should not be changed by fcn unless"
90 '" the user wants to terminate execution of lmdif."
91 '" in this case set iflag to a negative integer."
92 '""
93 '" m is a positive integer input variable set to the number"
94 '" of functions."
95 '""
96 '" n is a positive integer input variable set to the number"
97 '" of variables. n must not exceed m."
98 '""
99 '" x is an array of length n. on input x must contain"
100 '" an initial estimate of the solution vector. on output x"
101 '" contains the final estimate of the solution vector."
103 '" fvec is an output array of length m which contains"
104 '" the functions evaluated at the output x."
106 '" ftol is a nonnegative input variable. termination"
107 '" occurs when both the actual and predicted relative"
108 '" reductions in the sum of squares are at most ftol."
109 '" therefore, ftol measures the relative error desired"
110 '" in the sum of squares."
112 '" xtol is a nonnegative input variable. termination"
113 '" occurs when the relative error between two consecutive"
114 '" iterates is at most xtol. therefore, xtol measures the"
115 '" relative error desired in the approximate solution."
117 '" gtol is a nonnegative input variable. termination"
118 '" occurs when the cosine of the angle between fvec and"
119 '" any column of the jacobian is at most gtol in absolute"
120 '" value. therefore, gtol measures the orthogonality"
121 '" desired between the function vector and the columns"
122 '" of the jacobian."
124 '" maxfev is a positive integer input variable. termination"
125 '" occurs when the number of calls to fcn is at least"
126 '" maxfev by the end of an iteration."
128 '" epsfcn is an input variable used in determining a suitable"
129 '" step length for the forward-difference approximation. this"
130 '" approximation assumes that the relative errors in the"
131 '" functions are of the order of epsfcn. if epsfcn is less"
132 '" than the machine precision, it is assumed that the relative"
133 '" errors in the functions are of the order of the machine"
134 '" precision."
136 '" diag is an array of length n. if mode = 1 (see"
137 '" below), diag is internally set. if mode = 2, diag"
138 '" must contain positive entries that serve as"
139 '" multiplicative scale factors for the variables."
141 '" mode is an integer input variable. if mode = 1, the"
142 '" variables will be scaled internally. if mode = 2,"
143 '" the scaling is specified by the input diag. other"
144 '" values of mode are equivalent to mode = 1."
146 '" factor is a positive input variable used in determining the"
147 '" initial step bound. this bound is set to the product of"
148 '" factor and the euclidean norm of diag*x if nonzero, or else"
149 '" to factor itself. in most cases factor should lie in the"
150 '" interval (.1,100.). 100. is a generally recommended value."
152 '" nprint is an integer input variable that enables controlled"
153 '" printing of iterates if it is positive. in this case,"
154 '" fcn is called with iflag = 0 at the beginning of the first"
155 '" iteration and every nprint iterations thereafter and"
156 '" immediately prior to return, with x and fvec available"
157 '" for printing. if nprint is not positive, no special calls"
158 '" of fcn with iflag = 0 are made."
160 '" info is an integer output variable. if the user has"
161 '" terminated execution, info is set to the (negative)"
162 '" value of iflag. see description of fcn. otherwise,"
163 '" info is set as follows."
165 '" info = 0 improper input parameters."
167 '" info = 1 both actual and predicted relative reductions"
168 '" in the sum of squares are at most ftol."
170 '" info = 2 relative error between two consecutive iterates"
171 '" is at most xtol."
173 '" info = 3 conditions for info = 1 and info = 2 both hold."
175 '" info = 4 the cosine of the angle between fvec and any"
176 '" column of the jacobian is at most gtol in"
177 '" absolute value."
179 '" info = 5 number of calls to fcn has reached or"
180 '" exceeded maxfev."
182 '" info = 6 ftol is too small. no further reduction in"
183 '" the sum of squares is possible."
185 '" info = 7 xtol is too small. no further improvement in"
186 '" the approximate solution x is possible."
188 '" info = 8 gtol is too small. fvec is orthogonal to the"
189 '" columns of the jacobian to machine precision."
191 '" nfev is an integer output variable set to the number of"
192 '" calls to fcn."
194 '" fjac is an output m by n array. the upper n by n submatrix"
195 '" of fjac contains an upper triangular matrix r with"
196 '" diagonal elements of nonincreasing magnitude such that"
198 '" t t t"
199 '" p *(jac *jac)*p = r *r,"
201 '" where p is a permutation matrix and jac is the final"
202 '" calculated jacobian. column j of p is column ipvt(j)"
203 '" (see below) of the identity matrix. the lower trapezoidal"
204 '" part of fjac contains information generated during"
205 '" the computation of r."
207 '" ldfjac is a positive integer input variable not less than m"
208 '" which specifies the leading dimension of the array fjac."
210 '" ipvt is an integer output array of length n. ipvt"
211 '" defines a permutation matrix p such that jac*p = q*r,"
212 '" where jac is the final calculated jacobian, q is"
213 '" orthogonal (not stored), and r is upper triangular"
214 '" with diagonal elements of nonincreasing magnitude."
215 '" column j of p is column ipvt(j) of the identity matrix."
217 '" qtf is an output array of length n which contains"
218 '" the first n elements of the vector (q transpose)*fvec."
220 '" wa1, wa2, and wa3 are work arrays of length n."
222 '" wa4 is a work array of length m."
224 '" subprograms called"
226 '" user-supplied ...... fcn"
228 '" minpack-supplied ... dpmpar,enorm,fdjac2,lmpar,qrfac"
230 '" fortran-supplied ... dabs,dmax1,dmin1,dsqrt,mod"
232 '" argonne national laboratory. minpack project. march 1980."
233 '" burton s. garbow, kenneth e. hillstrom, jorge j. more"
235 '" **********"
237 '" epsmch is the machine precision."
239 (setf epsmch (dpmpar 1))
241 (setf info 0)
242 (setf iflag 0)
243 (setf nfev 0)
245 '" check the input parameters for errors."
248 (or (<= n 0)
249 (< m n)
250 (< ldfjac m)
251 (< ftol zero)
252 (< xtol zero)
253 (< gtol zero)
254 (<= maxfev 0)
255 (<= factor zero))
256 (go label300))
257 (if (/= mode 2) (go label20))
258 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
259 ((> j n) nil)
260 (tagbody
261 (if (<= (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%) zero)
262 (go label300))
263 label10))
264 label20
266 '" evaluate the function at the starting point"
267 '" and calculate its norm."
269 (setf iflag 1)
270 (multiple-value-bind (var-0 var-1 var-2 var-3 var-4)
271 (funcall fcn m n x fvec iflag)
272 (declare (ignore var-2 var-3))
273 (when var-0
274 (setf m var-0))
275 (when var-1
276 (setf n var-1))
277 (when var-4
278 (setf iflag var-4)))
279 (setf nfev 1)
280 (if (< iflag 0) (go label300))
281 (setf fnorm (enorm m fvec))
283 '" initialize levenberg-marquardt parameter and iteration counter."
285 (setf par zero)
286 (setf iter 1)
288 '" beginning of the outer loop."
290 label30
292 '" calculate the jacobian matrix."
294 (setf iflag 2)
295 (multiple-value-bind
296 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9)
297 (fdjac2 fcn m n x fvec fjac ldfjac iflag epsfcn wa4)
298 (declare (ignore var-0 var-3 var-4 var-5 var-6 var-8 var-9))
299 (setf m var-1)
300 (setf n var-2)
301 (setf iflag var-7))
302 (setf nfev (f2cl-lib:int-add nfev n))
303 (if (< iflag 0) (go label300))
305 '" if requested, call fcn to enable printing of iterates."
307 (if (<= nprint 0) (go label40))
308 (setf iflag 0)
309 (if (= (mod (f2cl-lib:int-sub iter 1) nprint) 0)
310 (multiple-value-bind (var-0 var-1 var-2 var-3 var-4)
311 (funcall fcn m n x fvec iflag)
312 (declare (ignore var-2 var-3))
313 (when var-0
314 (setf m var-0))
315 (when var-1
316 (setf n var-1))
317 (when var-4
318 (setf iflag var-4))))
319 (if (< iflag 0) (go label300))
320 label40
322 '" compute the qr factorization of the jacobian."
324 (qrfac m n fjac ldfjac f2cl-lib:%true% ipvt n wa1 wa2 wa3)
326 '" on the first iteration and if mode is 1, scale according"
327 '" to the norms of the columns of the initial jacobian."
329 (if (/= iter 1) (go label80))
330 (if (= mode 2) (go label60))
331 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
332 ((> j n) nil)
333 (tagbody
334 (setf (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%)
335 (f2cl-lib:fref wa2-%data% (j) ((1 n)) wa2-%offset%))
336 (if (= (f2cl-lib:fref wa2-%data% (j) ((1 n)) wa2-%offset%) zero)
337 (setf (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%)
338 one))
339 label50))
340 label60
342 '" on the first iteration, calculate the norm of the scaled x"
343 '" and initialize the step bound delta."
345 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
346 ((> j n) nil)
347 (tagbody
348 (setf (f2cl-lib:fref wa3-%data% (j) ((1 n)) wa3-%offset%)
349 (* (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%)
350 (f2cl-lib:fref x-%data% (j) ((1 n)) x-%offset%)))
351 label70))
352 (setf xnorm (enorm n wa3))
353 (setf delta (* factor xnorm))
354 (if (= delta zero) (setf delta factor))
355 label80
357 '" form (q transpose)*fvec and store the first n components in"
358 '" qtf."
360 (f2cl-lib:fdo (i 1 (f2cl-lib:int-add i 1))
361 ((> i m) nil)
362 (tagbody
363 (setf (f2cl-lib:fref wa4-%data% (i) ((1 m)) wa4-%offset%)
364 (f2cl-lib:fref fvec-%data% (i) ((1 m)) fvec-%offset%))
365 label90))
366 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
367 ((> j n) nil)
368 (tagbody
371 (f2cl-lib:fref fjac-%data%
372 (j j)
373 ((1 ldfjac) (1 n))
374 fjac-%offset%)
375 zero)
376 (go label120))
377 (setf sum zero)
378 (f2cl-lib:fdo (i j (f2cl-lib:int-add i 1))
379 ((> i m) nil)
380 (tagbody
381 (setf sum
382 (+ sum
384 (f2cl-lib:fref fjac-%data%
385 (i j)
386 ((1 ldfjac) (1 n))
387 fjac-%offset%)
388 (f2cl-lib:fref wa4-%data%
390 ((1 m))
391 wa4-%offset%))))
392 label100))
393 (setf temp
394 (/ (- sum)
395 (f2cl-lib:fref fjac-%data%
396 (j j)
397 ((1 ldfjac) (1 n))
398 fjac-%offset%)))
399 (f2cl-lib:fdo (i j (f2cl-lib:int-add i 1))
400 ((> i m) nil)
401 (tagbody
402 (setf (f2cl-lib:fref wa4-%data% (i) ((1 m)) wa4-%offset%)
403 (+ (f2cl-lib:fref wa4-%data% (i) ((1 m)) wa4-%offset%)
405 (f2cl-lib:fref fjac-%data%
406 (i j)
407 ((1 ldfjac) (1 n))
408 fjac-%offset%)
409 temp)))
410 label110))
411 label120
412 (setf (f2cl-lib:fref fjac-%data%
413 (j j)
414 ((1 ldfjac) (1 n))
415 fjac-%offset%)
416 (f2cl-lib:fref wa1-%data% (j) ((1 n)) wa1-%offset%))
417 (setf (f2cl-lib:fref qtf-%data% (j) ((1 n)) qtf-%offset%)
418 (f2cl-lib:fref wa4-%data% (j) ((1 m)) wa4-%offset%))
419 label130))
421 '" compute the norm of the scaled gradient."
423 (setf gnorm zero)
424 (if (= fnorm zero) (go label170))
425 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
426 ((> j n) nil)
427 (tagbody
428 (setf l (f2cl-lib:fref ipvt-%data% (j) ((1 n)) ipvt-%offset%))
429 (if (= (f2cl-lib:fref wa2-%data% (l) ((1 n)) wa2-%offset%) zero)
430 (go label150))
431 (setf sum zero)
432 (f2cl-lib:fdo (i 1 (f2cl-lib:int-add i 1))
433 ((> i j) nil)
434 (tagbody
435 (setf sum
436 (+ sum
438 (f2cl-lib:fref fjac-%data%
439 (i j)
440 ((1 ldfjac) (1 n))
441 fjac-%offset%)
443 (f2cl-lib:fref qtf-%data%
445 ((1 n))
446 qtf-%offset%)
447 fnorm))))
448 label140))
449 (setf gnorm
450 (f2cl-lib:dmax1 gnorm
451 (f2cl-lib:dabs
452 (/ sum
453 (f2cl-lib:fref wa2-%data%
455 ((1 n))
456 wa2-%offset%)))))
457 label150
458 label160))
459 label170
461 '" test for convergence of the gradient norm."
463 (if (<= gnorm gtol) (setf info 4))
464 (if (/= info 0) (go label300))
466 '" rescale if necessary."
468 (if (= mode 2) (go label190))
469 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
470 ((> j n) nil)
471 (tagbody
472 (setf (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%)
473 (f2cl-lib:dmax1
474 (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%)
475 (f2cl-lib:fref wa2-%data% (j) ((1 n)) wa2-%offset%)))
476 label180))
477 label190
479 '" beginning of the inner loop."
481 label200
483 '" determine the levenberg-marquardt parameter."
485 (multiple-value-bind
486 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9
487 var-10 var-11)
488 (lmpar n fjac ldfjac ipvt diag qtf delta par wa1 wa2 wa3 wa4)
489 (declare (ignore var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-8
490 var-9 var-10 var-11))
491 (setf par var-7))
493 '" store the direction p and x + p. calculate the norm of p."
495 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
496 ((> j n) nil)
497 (tagbody
498 (setf (f2cl-lib:fref wa1-%data% (j) ((1 n)) wa1-%offset%)
499 (- (f2cl-lib:fref wa1-%data% (j) ((1 n)) wa1-%offset%)))
500 (setf (f2cl-lib:fref wa2-%data% (j) ((1 n)) wa2-%offset%)
501 (+ (f2cl-lib:fref x-%data% (j) ((1 n)) x-%offset%)
502 (f2cl-lib:fref wa1-%data% (j) ((1 n)) wa1-%offset%)))
503 (setf (f2cl-lib:fref wa3-%data% (j) ((1 n)) wa3-%offset%)
504 (* (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%)
505 (f2cl-lib:fref wa1-%data% (j) ((1 n)) wa1-%offset%)))
506 label210))
507 (setf pnorm (enorm n wa3))
509 '" on the first iteration, adjust the initial step bound."
511 (if (= iter 1) (setf delta (f2cl-lib:dmin1 delta pnorm)))
513 '" evaluate the function at x + p and calculate its norm."
515 (setf iflag 1)
516 (multiple-value-bind (var-0 var-1 var-2 var-3 var-4)
517 (funcall fcn m n wa2 wa4 iflag)
518 (declare (ignore var-2 var-3))
519 (when var-0
520 (setf m var-0))
521 (when var-1
522 (setf n var-1))
523 (when var-4
524 (setf iflag var-4)))
525 (setf nfev (f2cl-lib:int-add nfev 1))
526 (if (< iflag 0) (go label300))
527 (setf fnorm1 (enorm m wa4))
529 '" compute the scaled actual reduction."
531 (setf actred (- one))
532 (if (< (* p1 fnorm1) fnorm)
533 (setf actred (- one (expt (/ fnorm1 fnorm) 2))))
535 '" compute the scaled predicted reduction and"
536 '" the scaled directional derivative."
538 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
539 ((> j n) nil)
540 (tagbody
541 (setf (f2cl-lib:fref wa3-%data% (j) ((1 n)) wa3-%offset%) zero)
542 (setf l (f2cl-lib:fref ipvt-%data% (j) ((1 n)) ipvt-%offset%))
543 (setf temp (f2cl-lib:fref wa1-%data% (l) ((1 n)) wa1-%offset%))
544 (f2cl-lib:fdo (i 1 (f2cl-lib:int-add i 1))
545 ((> i j) nil)
546 (tagbody
547 (setf (f2cl-lib:fref wa3-%data% (i) ((1 n)) wa3-%offset%)
548 (+ (f2cl-lib:fref wa3-%data% (i) ((1 n)) wa3-%offset%)
550 (f2cl-lib:fref fjac-%data%
551 (i j)
552 ((1 ldfjac) (1 n))
553 fjac-%offset%)
554 temp)))
555 label220))
556 label230))
557 (setf temp1 (/ (enorm n wa3) fnorm))
558 (setf temp2 (/ (* (f2cl-lib:dsqrt par) pnorm) fnorm))
559 (setf prered (+ (expt temp1 2) (/ (expt temp2 2) p5)))
560 (setf dirder (- (+ (expt temp1 2) (expt temp2 2))))
562 '" compute the ratio of the actual to the predicted"
563 '" reduction."
565 (setf ratio zero)
566 (if (/= prered zero) (setf ratio (/ actred prered)))
568 '" update the step bound."
570 (if (> ratio p25) (go label240))
571 (if (>= actred zero) (setf temp p5))
572 (if (< actred zero)
573 (setf temp (/ (* p5 dirder) (+ dirder (* p5 actred)))))
574 (if (or (>= (* p1 fnorm1) fnorm) (< temp p1)) (setf temp p1))
575 (setf delta (* temp (f2cl-lib:dmin1 delta (/ pnorm p1))))
576 (setf par (/ par temp))
577 (go label260)
578 label240
579 (if (and (/= par zero) (< ratio p75)) (go label250))
580 (setf delta (/ pnorm p5))
581 (setf par (* p5 par))
582 label250
583 label260
585 '" test for successful iteration."
587 (if (< ratio p0001) (go label290))
589 '" successful iteration. update x, fvec, and their norms."
591 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
592 ((> j n) nil)
593 (tagbody
594 (setf (f2cl-lib:fref x-%data% (j) ((1 n)) x-%offset%)
595 (f2cl-lib:fref wa2-%data% (j) ((1 n)) wa2-%offset%))
596 (setf (f2cl-lib:fref wa2-%data% (j) ((1 n)) wa2-%offset%)
597 (* (f2cl-lib:fref diag-%data% (j) ((1 n)) diag-%offset%)
598 (f2cl-lib:fref x-%data% (j) ((1 n)) x-%offset%)))
599 label270))
600 (f2cl-lib:fdo (i 1 (f2cl-lib:int-add i 1))
601 ((> i m) nil)
602 (tagbody
603 (setf (f2cl-lib:fref fvec-%data% (i) ((1 m)) fvec-%offset%)
604 (f2cl-lib:fref wa4-%data% (i) ((1 m)) wa4-%offset%))
605 label280))
606 (setf xnorm (enorm n wa2))
607 (setf fnorm fnorm1)
608 (setf iter (f2cl-lib:int-add iter 1))
609 label290
611 '" tests for convergence."
614 (and (<= (f2cl-lib:dabs actred) ftol)
615 (<= prered ftol)
616 (<= (* p5 ratio) one))
617 (setf info 1))
618 (if (<= delta (* xtol xnorm)) (setf info 2))
620 (and (<= (f2cl-lib:dabs actred) ftol)
621 (<= prered ftol)
622 (<= (* p5 ratio) one)
623 (= info 2))
624 (setf info 3))
625 (if (/= info 0) (go label300))
627 '" tests for termination and stringent tolerances."
629 (if (>= nfev maxfev) (setf info 5))
631 (and (<= (f2cl-lib:dabs actred) epsmch)
632 (<= prered epsmch)
633 (<= (* p5 ratio) one))
634 (setf info 6))
635 (if (<= delta (* epsmch xnorm)) (setf info 7))
636 (if (<= gnorm epsmch) (setf info 8))
637 (if (/= info 0) (go label300))
639 '" end of the inner loop. repeat if iteration unsuccessful."
641 (if (< ratio p0001) (go label200))
643 '" end of the outer loop."
645 (go label30)
646 label300
648 '" termination, either normal or user imposed."
650 (if (< iflag 0) (setf info iflag))
651 (setf iflag 0)
652 (if (> nprint 0)
653 (multiple-value-bind (var-0 var-1 var-2 var-3 var-4)
654 (funcall fcn m n x fvec iflag)
655 (declare (ignore var-2 var-3))
656 (when var-0
657 (setf m var-0))
658 (when var-1
659 (setf n var-1))
660 (when var-4
661 (setf iflag var-4))))
662 (go end_label)
664 '" last card of subroutine lmdif."
666 end_label
667 (return
668 (values nil
682 info
683 nfev
691 nil))))))
693 (in-package #:cl-user)
694 #+#.(cl:if (cl:find-package '#:f2cl) '(and) '(or))
695 (eval-when (:load-toplevel :compile-toplevel :execute)
696 (setf (gethash 'fortran-to-lisp::lmdif fortran-to-lisp::*f2cl-function-info*)
697 (fortran-to-lisp::make-f2cl-finfo
698 :arg-types '(t (fortran-to-lisp::integer4)
699 (fortran-to-lisp::integer4) (array double-float (*))
700 (array double-float (*)) (double-float) (double-float)
701 (double-float) (fortran-to-lisp::integer4)
702 (double-float) (array double-float (*))
703 (fortran-to-lisp::integer4) (double-float)
704 (fortran-to-lisp::integer4) (fortran-to-lisp::integer4)
705 (fortran-to-lisp::integer4) (array double-float (*))
706 (fortran-to-lisp::integer4)
707 (array fortran-to-lisp::integer4 (*))
708 (array double-float (*)) (array double-float (*))
709 (array double-float (*)) (array double-float (*))
710 (array double-float (*)))
711 :return-values '(nil fortran-to-lisp::m fortran-to-lisp::n nil nil
712 nil nil nil nil nil nil nil nil nil
713 fortran-to-lisp::info fortran-to-lisp::nfev nil nil
714 nil nil nil nil nil nil)
715 :calls '(fortran-to-lisp::lmpar fortran-to-lisp::qrfac
716 fortran-to-lisp::fdjac2 fortran-to-lisp::enorm
717 fortran-to-lisp::dpmpar))))