1 SUBROUTINE TANGNF
(RHOLEN
,Y
,YP
,YPOLD
,A
,QR
,ALPHA
,TZ
,PIVOT
,
2 $ NFE
,N
,IFLAG
,PAR
,IPAR
)
4 C THIS SUBROUTINE BUILDS THE JACOBIAN MATRIX OF THE HOMOTOPY MAP,
5 C COMPUTES A QR DECOMPOSITION OF THAT MATRIX, AND THEN CALCULATES THE
6 C (UNIT) TANGENT VECTOR AND THE NEWTON STEP.
10 C RHOLEN < 0 IF THE NORM OF THE HOMOTOPY MAP EVALUATED AT
11 C (A, LAMBDA, X) IS TO BE COMPUTED. IF RHOLEN >= 0 THE NORM IS NOT
12 C COMPUTED AND RHOLEN IS NOT CHANGED.
14 C Y(1:N+1) = CURRENT POINT (LAMBDA(S), X(S)).
16 C YPOLD(1:N+1) = UNIT TANGENT VECTOR AT PREVIOUS POINT ON THE ZERO
17 C CURVE OF THE HOMOTOPY MAP.
19 C A(1:*) = PARAMETER VECTOR IN THE HOMOTOPY MAP.
21 C QR(1:N,1:N+2), ALPHA(1:N), TZ(1:N+1), PIVOT(1:N+1) ARE WORK ARRAYS
22 C USED FOR THE QR FACTORIZATION.
24 C NFE = NUMBER OF JACOBIAN MATRIX EVALUATIONS = NUMBER OF HOMOTOPY
25 C FUNCTION EVALUATIONS.
29 C IFLAG = -2, -1, OR 0, INDICATING THE PROBLEM TYPE.
31 C PAR(1:*) AND IPAR(1:*) ARE ARRAYS FOR (OPTIONAL) USER PARAMETERS,
32 C WHICH ARE SIMPLY PASSED THROUGH TO THE USER WRITTEN SUBROUTINES
37 C RHOLEN = ||RHO(A, LAMBDA(S), X(S)|| IF RHOLEN < 0 ON INPUT.
38 C OTHERWISE RHOLEN IS UNCHANGED.
40 C Y, YPOLD, A, N ARE UNCHANGED.
42 C YP(1:N+1) = DY/DS = UNIT TANGENT VECTOR TO INTEGRAL CURVE OF
43 C D(HOMOTOPY MAP)/DS = 0 AT Y(S) = (LAMBDA(S), X(S)) .
45 C TZ = THE NEWTON STEP = -(PSEUDO INVERSE OF (D RHO(A,Y(S))/D LAMBDA ,
46 C D RHO(A,Y(S))/DX)) * RHO(A,Y(S)) .
48 C NFE HAS BEEN INCRMENTED BY 1.
50 C IFLAG IS UNCHANGED, UNLESS THE QR FACTORIZATION DETECTS A RANK < N,
51 C IN WHICH CASE THE TANGENT AND NEWTON STEP VECTORS ARE NOT COMPUTED
52 C AND TANGNF RETURNS WITH IFLAG = 4 .
55 C CALLS DDOT , DNRM2 , F (OR RHO ), FJAC (OR RHOJAC ).
57 DOUBLE PRECISION ALPHAK
,BETA
,DDOT
,DNRM2
,LAMBDA
,QRKK
,RHOLEN
,
59 INTEGER I
,IFLAG
,J
,JBAR
,K
,KP1
,N
,NFE
,NP1
,NP2
61 C ***** ARRAY DECLARATIONS. *****
63 DOUBLE PRECISION Y
(N
+1),YP
(N
+1),YPOLD
(N
+1),A
(N
),PAR
(1)
66 C ARRAYS FOR COMPUTING THE JACOBIAN MATRIX AND ITS KERNEL.
67 DOUBLE PRECISION QR
(N
,N
+2),ALPHA
(N
),TZ
(N
+1)
70 C ***** END OF DIMENSIONAL INFORMATION. *****
77 C NFE CONTAINS THE NUMBER OF JACOBIAN EVALUATIONS.
78 C * * * * * * * * * * * * * * * * *
80 C COMPUTE THE JACOBIAN MATRIX, STORE IT AND HOMOTOPY MAP IN QR.
82 IF (IFLAG
.EQ
. -2) THEN
84 C QR = ( D RHO(A,LAMBDA,X)/D LAMBDA , D RHO(A,LAMBDA,X)/DX ,
88 CALL RHOJAC
(A
,LAMBDA
,Y
(2),QR
(1,K
),K
,PAR
,IPAR
)
90 CALL RHO
(A
,LAMBDA
,Y
(2),QR
(1,NP2
),PAR
,IPAR
)
93 IF (IFLAG
.EQ
. 0) THEN
95 C QR = ( A - F(X), I - LAMBDA*DF(X) ,
96 C X - A + LAMBDA*(A - F(X)) ) .
102 100 QR
(J
,NP2
)=Y
(J
+1)-SIGMA
+LAMBDA*BETA
107 110 QR
(J
,KP1
)=-LAMBDA*TZ
(J
)
108 120 QR
(K
,KP1
)=1.0+QR
(K
,KP1
)
111 C QR = ( F(X) - X + A, LAMBDA*DF(X) + (1 - LAMBDA)*I ,
112 C X - A + LAMBDA*(F(X) - X + A) ) .
118 150 QR
(J
,NP2
)=SIGMA
+LAMBDA*BETA
123 160 QR
(J
,KP1
)=LAMBDA*TZ
(J
)
124 170 QR
(K
,KP1
)=1.0-LAMBDA
+QR
(K
,KP1
)
128 C * * * * * * * * * * * * * * * * *
129 C COMPUTE THE NORM OF THE HOMOTOPY MAP IF IT WAS REQUESTED.
130 IF (RHOLEN
.LT
. 0.0) RHOLEN
=DNRM2
(N
,QR
(1,NP2
),1)
132 C REDUCE THE JACOBIAN MATRIX TO UPPER TRIANGULAR FORM.
134 C THE FOLLOWING CODE IS A MODIFICATION OF THE ALGOL PROCEDURE
135 C DECOMPOSE IN P. BUSINGER AND G. H. GOLUB, LINEAR LEAST
136 C SQUARES SOLUTIONS BY HOUSEHOLDER TRANSFORMATIONS,
137 C NUMER. MATH. 7 (1965) 269-276.
140 YP
(J
)=DDOT
(N
,QR
(1,J
),1,QR
(1,J
),1)
147 IF (SIGMA
.GE
. YP
(J
)) GO TO 240
151 IF (JBAR
.EQ
. K
) GO TO 260
162 C END OF COLUMN INTERCHANGE.
163 260 SIGMA
=DDOT
(N
-K
+1,QR
(K
,K
),1,QR
(K
,K
),1)
164 IF (SIGMA
.EQ
. 0.0) THEN
168 270 IF (K
.EQ
. N
) GO TO 300
171 IF (QRKK
.LT
. 0.0) ALPHAK
=-ALPHAK
173 BETA
=1.0/(SIGMA
-QRKK*ALPHAK
)
176 SIGMA
=BETA*DDOT
(N
-K
+1,QR
(K
,K
),1,QR
(K
,J
),1)
178 QR
(I
,J
)=QR
(I
,J
)-QR
(I
,K
)*SIGMA
180 IF (J
.LT
. NP2
) YP
(J
)=YP
(J
)-QR
(K
,J
)**2
186 C COMPUTE KERNEL OF JACOBIAN, WHICH SPECIFIES YP=DY/DS.
191 330 SUM
=SUM
+QR
(I
,J
)*TZ
(J
)
192 340 TZ
(I
)=-SUM
/ALPHA
(I
)
193 YPNORM
=DNRM2
(NP1
,TZ
,1)
195 360 YP
(PIVOT
(K
))=TZ
(K
)/YPNORM
196 IF (DDOT
(NP1
,YP
,1,YPOLD
,1) .GE
. 0.0) GO TO 380
199 C YP IS THE UNIT TANGENT VECTOR IN THE CORRECT DIRECTION.
201 C COMPUTE THE MINIMUM NORM SOLUTION OF [D RHO(Y(S))] V = -RHO(Y(S)).
202 C V IS GIVEN BY P - (P,Q)Q , WHERE P IS ANY SOLUTION OF
203 C [D RHO] V = -RHO AND Q IS A UNIT VECTOR IN THE KERNEL OF [D RHO].
206 SUM
=QR
(I
,NP1
)+QR
(I
,NP2
)
208 430 SUM
=SUM
+QR
(I
,J
)*ALPHA
(J
)
209 440 ALPHA
(I
)=-SUM
/ALPHA
(I
)
211 450 TZ
(PIVOT
(K
))=ALPHA
(K
)
213 C TZ NOW CONTAINS A PARTICULAR SOLUTION P, AND YP CONTAINS A VECTOR Q
214 C IN THE KERNEL(THE TANGENT).
215 SIGMA
=DDOT
(NP1
,TZ
,1,YP
,1)
217 TZ
(J
)=TZ
(J
)-SIGMA*YP
(J
)
219 C TZ IS THE NEWTON STEP FROM THE CURRENT POINT Y(S) = (LAMBDA(S), X(S)).