Rename *ll* and *ul* to ll and ul in defint
[maxima.git] / share / minpack / lisp / hybrj1.lisp
blob94a0ba703b66c46582d7ec68085acb453259c88f
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 ((factor 100.0) (one 1.0) (zero 0.0))
21 (declare (type (double-float) factor one zero))
22 (defun hybrj1 (fcn n x fvec fjac ldfjac tol info wa lwa)
23 (declare (type (double-float) tol)
24 (type (array double-float (*)) wa fjac fvec x)
25 (type (f2cl-lib:integer4) lwa info ldfjac n))
26 (f2cl-lib:with-multi-array-data
27 ((x double-float x-%data% x-%offset%)
28 (fvec double-float fvec-%data% fvec-%offset%)
29 (fjac double-float fjac-%data% fjac-%offset%)
30 (wa double-float wa-%data% wa-%offset%))
31 (prog ((xtol 0.0) (j 0) (lr 0) (maxfev 0) (mode 0) (nfev 0) (njev 0)
32 (nprint 0))
33 (declare (type (f2cl-lib:integer4) nprint njev nfev mode maxfev lr j)
34 (type (double-float) xtol))
35 '" **********"
36 '""
37 '" subroutine hybrj1"
38 '""
39 '" the purpose of hybrj1 is to find a zero of a system of"
40 '" n nonlinear functions in n variables by a modification"
41 '" of the powell hybrid method. this is done by using the"
42 '" more general nonlinear equation solver hybrj. the user"
43 '" must provide a subroutine which calculates the functions"
44 '" and the jacobian."
45 '""
46 '" the subroutine statement is"
47 '""
48 '" subroutine hybrj1(fcn,n,x,fvec,fjac,ldfjac,tol,info,wa,lwa)"
49 '""
50 '" where"
51 '""
52 '" fcn is the name of the user-supplied subroutine which"
53 '" calculates the functions and the jacobian. fcn must"
54 '" be declared in an external statement in the user"
55 '" calling program, and should be written as follows."
56 '""
57 '" subroutine fcn(n,x,fvec,fjac,ldfjac,iflag)"
58 '" integer n,ldfjac,iflag"
59 '" double precision x(n),fvec(n),fjac(ldfjac,n)"
60 '" ----------"
61 '" if iflag = 1 calculate the functions at x and"
62 '" return this vector in fvec. do not alter fjac."
63 '" if iflag = 2 calculate the jacobian at x and"
64 '" return this matrix in fjac. do not alter fvec."
65 '" ---------"
66 '" return"
67 '" end"
68 '""
69 '" the value of iflag should not be changed by fcn unless"
70 '" the user wants to terminate execution of hybrj1."
71 '" in this case set iflag to a negative integer."
72 '""
73 '" n is a positive integer input variable set to the number"
74 '" of functions and variables."
75 '""
76 '" x is an array of length n. on input x must contain"
77 '" an initial estimate of the solution vector. on output x"
78 '" contains the final estimate of the solution vector."
79 '""
80 '" fvec is an output array of length n which contains"
81 '" the functions evaluated at the output x."
82 '""
83 '" fjac is an output n by n array which contains the"
84 '" orthogonal matrix q produced by the qr factorization"
85 '" of the final approximate jacobian."
86 '""
87 '" ldfjac is a positive integer input variable not less than n"
88 '" which specifies the leading dimension of the array fjac."
89 '""
90 '" tol is a nonnegative input variable. termination occurs"
91 '" when the algorithm estimates that the relative error"
92 '" between x and the solution is at most tol."
93 '""
94 '" info is an integer output variable. if the user has"
95 '" terminated execution, info is set to the (negative)"
96 '" value of iflag. see description of fcn. otherwise,"
97 '" info is set as follows."
98 '""
99 '" info = 0 improper input parameters."
101 '" info = 1 algorithm estimates that the relative error"
102 '" between x and the solution is at most tol."
104 '" info = 2 number of calls to fcn with iflag = 1 has"
105 '" reached 100*(n+1)."
107 '" info = 3 tol is too small. no further improvement in"
108 '" the approximate solution x is possible."
110 '" info = 4 iteration is not making good progress."
112 '" wa is a work array of length lwa."
114 '" lwa is a positive integer input variable not less than"
115 '" (n*(n+13))/2."
117 '" subprograms called"
119 '" user-supplied ...... fcn"
121 '" minpack-supplied ... hybrj"
123 '" argonne national laboratory. minpack project. march 1980."
124 '" burton s. garbow, kenneth e. hillstrom, jorge j. more"
126 '" **********"
127 (setf info 0)
129 '" check the input parameters for errors."
132 (or (<= n 0)
133 (< ldfjac n)
134 (< tol zero)
135 (< lwa (the f2cl-lib:integer4 (truncate (* n (+ n 13)) 2))))
136 (go label20))
138 '" call hybrj."
140 (setf maxfev (f2cl-lib:int-mul 100 (f2cl-lib:int-add n 1)))
141 (setf xtol tol)
142 (setf mode 2)
143 (f2cl-lib:fdo (j 1 (f2cl-lib:int-add j 1))
144 ((> j n) nil)
145 (tagbody
146 (setf (f2cl-lib:fref wa-%data% (j) ((1 lwa)) wa-%offset%) one)
147 label10))
148 (setf nprint 0)
149 (setf lr (the f2cl-lib:integer4 (truncate (* n (+ n 1)) 2)))
150 (multiple-value-bind
151 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9
152 var-10 var-11 var-12 var-13 var-14 var-15 var-16 var-17 var-18
153 var-19 var-20 var-21)
154 (hybrj fcn n x fvec fjac ldfjac xtol maxfev
155 (f2cl-lib:array-slice wa double-float (1) ((1 lwa))) mode factor
156 nprint info nfev njev
157 (f2cl-lib:array-slice wa
158 double-float
159 ((+ (f2cl-lib:int-mul 6 n) 1))
160 ((1 lwa)))
161 lr (f2cl-lib:array-slice wa double-float ((+ n 1)) ((1 lwa)))
162 (f2cl-lib:array-slice wa
163 double-float
164 ((+ (f2cl-lib:int-mul 2 n) 1))
165 ((1 lwa)))
166 (f2cl-lib:array-slice wa
167 double-float
168 ((+ (f2cl-lib:int-mul 3 n) 1))
169 ((1 lwa)))
170 (f2cl-lib:array-slice wa
171 double-float
172 ((+ (f2cl-lib:int-mul 4 n) 1))
173 ((1 lwa)))
174 (f2cl-lib:array-slice wa
175 double-float
176 ((+ (f2cl-lib:int-mul 5 n) 1))
177 ((1 lwa))))
178 (declare (ignore var-0 var-2 var-3 var-4 var-6 var-7 var-8 var-9
179 var-10 var-11 var-15 var-16 var-17 var-18 var-19
180 var-20 var-21))
181 (setf n var-1)
182 (setf ldfjac var-5)
183 (setf info var-12)
184 (setf nfev var-13)
185 (setf njev var-14))
186 (if (= info 5) (setf info 4))
187 label20
188 (go end_label)
190 '" last card of subroutine hybrj1."
192 end_label
193 (return (values nil n nil nil nil ldfjac nil info nil nil))))))
195 (in-package #:cl-user)
196 #+#.(cl:if (cl:find-package '#:f2cl) '(and) '(or))
197 (eval-when (:load-toplevel :compile-toplevel :execute)
198 (setf (gethash 'fortran-to-lisp::hybrj1
199 fortran-to-lisp::*f2cl-function-info*)
200 (fortran-to-lisp::make-f2cl-finfo
201 :arg-types '(t (fortran-to-lisp::integer4) (array double-float (*))
202 (array double-float (*)) (array double-float (*))
203 (fortran-to-lisp::integer4) (double-float)
204 (fortran-to-lisp::integer4) (array double-float (*))
205 (fortran-to-lisp::integer4))
206 :return-values '(nil fortran-to-lisp::n nil nil nil
207 fortran-to-lisp::ldfjac nil fortran-to-lisp::info
208 nil nil)
209 :calls '(fortran-to-lisp::hybrj))))