1 subroutine lmpar
(n
,r
,ldr
,ipvt
,diag
,qtb
,delta
,par
,x
,sdiag
,wa1
,
5 double precision delta
,par
6 double precision r
(ldr
,n
),diag
(n
),qtb
(n
),x
(n
),sdiag
(n
),wa1
(n
),
12 c given an m by n matrix a, an n by n nonsingular diagonal
13 c matrix d, an m-vector b, and a positive number delta,
14 c the problem is to determine a value for the parameter
15 c par such that if x solves the system
17 c a*x = b , sqrt(par)*d*x = 0 ,
19 c in the least squares sense, and dxnorm is the euclidean
20 c norm of d*x, then either par is zero and
22 c (dxnorm-delta) .le. 0.1*delta ,
24 c or par is positive and
26 c abs(dxnorm-delta) .le. 0.1*delta .
28 c this subroutine completes the solution of the problem
29 c if it is provided with the necessary information from the
30 c qr factorization, with column pivoting, of a. that is, if
31 c a*p = q*r, where p is a permutation matrix, q has orthogonal
32 c columns, and r is an upper triangular matrix with diagonal
33 c elements of nonincreasing magnitude, then lmpar expects
34 c the full upper triangle of r, the permutation matrix p,
35 c and the first n components of (q transpose)*b. on output
36 c lmpar also provides an upper triangular matrix s such that
39 c p *(a *a + par*d*d)*p = s *s .
41 c s is employed within lmpar and may be of separate interest.
43 c only a few iterations are generally needed for convergence
44 c of the algorithm. if, however, the limit of 10 iterations
45 c is reached, then the output par will contain the best
46 c value obtained so far.
48 c the subroutine statement is
50 c subroutine lmpar(n,r,ldr,ipvt,diag,qtb,delta,par,x,sdiag,
55 c n is a positive integer input variable set to the order of r.
57 c r is an n by n array. on input the full upper triangle
58 c must contain the full upper triangle of the matrix r.
59 c on output the full upper triangle is unaltered, and the
60 c strict lower triangle contains the strict upper triangle
61 c (transposed) of the upper triangular matrix s.
63 c ldr is a positive integer input variable not less than n
64 c which specifies the leading dimension of the array r.
66 c ipvt is an integer input array of length n which defines the
67 c permutation matrix p such that a*p = q*r. column j of p
68 c is column ipvt(j) of the identity matrix.
70 c diag is an input array of length n which must contain the
71 c diagonal elements of the matrix d.
73 c qtb is an input array of length n which must contain the first
74 c n elements of the vector (q transpose)*b.
76 c delta is a positive input variable which specifies an upper
77 c bound on the euclidean norm of d*x.
79 c par is a nonnegative variable. on input par contains an
80 c initial estimate of the levenberg-marquardt parameter.
81 c on output par contains the final estimate.
83 c x is an output array of length n which contains the least
84 c squares solution of the system a*x = b, sqrt(par)*d*x = 0,
87 c sdiag is an output array of length n which contains the
88 c diagonal elements of the upper triangular matrix s.
90 c wa1 and wa2 are work arrays of length n.
94 c minpack-supplied ... dpmpar,enorm,qrsolv
96 c fortran-supplied ... dabs,dmax1,dmin1,dsqrt
98 c argonne national laboratory. minpack project. march 1980.
99 c burton s. garbow, kenneth e. hillstrom, jorge j. more
102 integer i
,iter
,j
,jm1
,jp1
,k
,l
,nsing
103 double precision dxnorm
,dwarf
,fp
,gnorm
,parc
,parl
,paru
,p1
,p001
,
105 double precision dpmpar
,enorm
106 data p1
,p001
,zero
/1.0d
-1,1.0d
-3,0.0d0
/
108 c dwarf is the smallest positive magnitude.
112 c compute and store in x the gauss-newton direction. if the
113 c jacobian is rank-deficient, obtain a least squares solution.
118 if (r
(j
,j
) .eq
. zero
.and
. nsing
.eq
. n
) nsing
= j
- 1
119 if (nsing
.lt
. n
) wa1
(j
) = zero
121 if (nsing
.lt
. 1) go to 50
124 wa1
(j
) = wa1
(j
)/r
(j
,j
)
127 if (jm1
.lt
. 1) go to 30
129 wa1
(i
) = wa1
(i
) - r
(i
,j
)*temp
139 c initialize the iteration counter.
140 c evaluate the function at the origin, and test
141 c for acceptance of the gauss-newton direction.
145 wa2
(j
) = diag
(j
)*x
(j
)
147 dxnorm
= enorm
(n
,wa2
)
149 if (fp
.le
. p1*delta
) go to 220
151 c if the jacobian is not rank deficient, the newton
152 c step provides a lower bound, parl, for the zero of
153 c the function. otherwise set this bound to zero.
156 if (nsing
.lt
. n
) go to 120
159 wa1
(j
) = diag
(l
)*(wa2
(l
)/dxnorm
)
164 if (jm1
.lt
. 1) go to 100
166 sum
= sum
+ r
(i
,j
)*wa1
(i
)
169 wa1
(j
) = (wa1
(j
) - sum
)/r
(j
,j
)
172 parl
= ((fp
/delta
)/temp
)/temp
175 c calculate an upper bound, paru, for the zero of the function.
180 sum
= sum
+ r
(i
,j
)*qtb
(i
)
187 if (paru
.eq
. zero
) paru
= dwarf
/dmin1
(delta
,p1
)
189 c if the input par lies outside of the interval (parl,paru),
190 c set par to the closer endpoint.
192 par
= dmax1
(par
,parl
)
193 par
= dmin1
(par
,paru
)
194 if (par
.eq
. zero
) par
= gnorm
/dxnorm
196 c beginning of an iteration.
201 c evaluate the function at the current value of par.
203 if (par
.eq
. zero
) par
= dmax1
(dwarf
,p001*paru
)
206 wa1
(j
) = temp*diag
(j
)
208 call qrsolv
(n
,r
,ldr
,ipvt
,wa1
,qtb
,x
,sdiag
,wa2
)
210 wa2
(j
) = diag
(j
)*x
(j
)
212 dxnorm
= enorm
(n
,wa2
)
216 c if the function is small enough, accept the current value
217 c of par. also test for the exceptional cases where parl
218 c is zero or the number of iterations has reached 10.
220 if (dabs
(fp
) .le
. p1*delta
221 * .or
. parl
.eq
. zero
.and
. fp
.le
. temp
222 * .and
. temp
.lt
. zero
.or
. iter
.eq
. 10) go to 220
224 c compute the newton correction.
228 wa1
(j
) = diag
(l
)*(wa2
(l
)/dxnorm
)
231 wa1
(j
) = wa1
(j
)/sdiag
(j
)
234 if (n
.lt
. jp1
) go to 200
236 wa1
(i
) = wa1
(i
) - r
(i
,j
)*temp
241 parc
= ((fp
/delta
)/temp
)/temp
243 c depending on the sign of the function, update parl or paru.
245 if (fp
.gt
. zero
) parl
= dmax1
(parl
,par
)
246 if (fp
.lt
. zero
) paru
= dmin1
(paru
,par
)
248 c compute an improved estimate for par.
250 par
= dmax1
(parl
,par
+parc
)
252 c end of an iteration.
259 if (iter
.eq
. 0) par
= zero
262 c last card of subroutine lmpar.