1 subroutine dogleg
(n
,r
,lr
,diag
,qtb
,delta
,x
,wa1
,wa2
)
4 double precision r
(lr
),diag
(n
),qtb
(n
),x
(n
),wa1
(n
),wa2
(n
)
9 c given an m by n matrix a, an n by n nonsingular diagonal
10 c matrix d, an m-vector b, and a positive number delta, the
11 c problem is to determine the convex combination x of the
12 c gauss-newton and scaled gradient directions that minimizes
13 c (a*x - b) in the least squares sense, subject to the
14 c restriction that the euclidean norm of d*x be at most delta.
16 c this subroutine completes the solution of the problem
17 c if it is provided with the necessary information from the
18 c qr factorization of a. that is, if a = q*r, where q has
19 c orthogonal columns and r is an upper triangular matrix,
20 c then dogleg expects the full upper triangle of r and
21 c the first n components of (q transpose)*b.
23 c the subroutine statement is
25 c subroutine dogleg(n,r,lr,diag,qtb,delta,x,wa1,wa2)
29 c n is a positive integer input variable set to the order of r.
31 c r is an input array of length lr which must contain the upper
32 c triangular matrix r stored by rows.
34 c lr is a positive integer input variable not less than
37 c diag is an input array of length n which must contain the
38 c diagonal elements of the matrix d.
40 c qtb is an input array of length n which must contain the first
41 c n elements of the vector (q transpose)*b.
43 c delta is a positive input variable which specifies an upper
44 c bound on the euclidean norm of d*x.
46 c x is an output array of length n which contains the desired
47 c convex combination of the gauss-newton direction and the
48 c scaled gradient direction.
50 c wa1 and wa2 are work arrays of length n.
54 c minpack-supplied ... dpmpar,enorm
56 c fortran-supplied ... dabs,dmax1,dmin1,dsqrt
58 c argonne national laboratory. minpack project. march 1980.
59 c burton s. garbow, kenneth e. hillstrom, jorge j. more
62 integer i
,j
,jj
,jp1
,k
,l
63 double precision alpha
,bnorm
,epsmch
,gnorm
,one
,qnorm
,sgnorm
,sum
,
65 double precision dpmpar
,enorm
66 data one
,zero
/1.0d0
,0.0d0
/
68 c epsmch is the machine precision.
72 c first, calculate the gauss-newton direction.
74 jj
= (n*
(n
+ 1))/2 + 1
81 if (n
.lt
. jp1
) go to 20
88 if (temp
.ne
. zero
) go to 40
91 temp
= dmax1
(temp
,dabs
(r
(l
)))
95 if (temp
.eq
. zero
) temp
= epsmch
97 x
(j
) = (qtb
(j
) - sum
)/temp
100 c test whether the gauss-newton direction is acceptable.
104 wa2
(j
) = diag
(j
)*x
(j
)
107 if (qnorm
.le
. delta
) go to 140
109 c the gauss-newton direction is not acceptable.
110 c next, calculate the scaled gradient direction.
116 wa1
(i
) = wa1
(i
) + r
(l
)*temp
119 wa1
(j
) = wa1
(j
)/diag
(j
)
122 c calculate the norm of the scaled gradient and test for
123 c the special case in which the scaled gradient is zero.
128 if (gnorm
.eq
. zero
) go to 120
130 c calculate the point along the scaled gradient
131 c at which the quadratic is minimized.
134 wa1
(j
) = (wa1
(j
)/gnorm
)/diag
(j
)
140 sum
= sum
+ r
(l
)*wa1
(i
)
146 sgnorm
= (gnorm
/temp
)/temp
148 c test whether the scaled gradient direction is acceptable.
151 if (sgnorm
.ge
. delta
) go to 120
153 c the scaled gradient direction is not acceptable.
154 c finally, calculate the point along the dogleg
155 c at which the quadratic is minimized.
158 temp
= (bnorm
/gnorm
)*(bnorm
/qnorm
)*(sgnorm
/delta
)
159 temp
= temp
- (delta
/qnorm
)*(sgnorm
/delta
)**2
160 * + dsqrt
((temp
-(delta
/qnorm
))**2
161 * +(one
-(delta
/qnorm
)**2)*(one
-(sgnorm
/delta
)**2))
162 alpha
= ((delta
/qnorm
)*(one
- (sgnorm
/delta
)**2))/temp
165 c form appropriate convex combination of the gauss-newton
166 c direction and the scaled gradient direction.
168 temp
= (one
- alpha
)*dmin1
(sgnorm
,delta
)
170 x
(j
) = temp*wa1
(j
) + alpha*x
(j
)
175 c last card of subroutine dogleg.