1 SUBROUTINE MCSTEP
(STX
,FX
,DX
,STY
,FY
,DY
,STP
,FP
,DP
,BRACKT
,
4 DOUBLE PRECISION STX
,FX
,DX
,STY
,FY
,DY
,STP
,FP
,DP
,STPMIN
,STPMAX
9 C THE PURPOSE OF MCSTEP IS TO COMPUTE A SAFEGUARDED STEP FOR
10 C A LINESEARCH AND TO UPDATE AN INTERVAL OF UNCERTAINTY FOR
11 C A MINIMIZER OF THE FUNCTION.
13 C THE PARAMETER STX CONTAINS THE STEP WITH THE LEAST FUNCTION
14 C VALUE. THE PARAMETER STP CONTAINS THE CURRENT STEP. IT IS
15 C ASSUMED THAT THE DERIVATIVE AT STX IS NEGATIVE IN THE
16 C DIRECTION OF THE STEP. IF BRACKT IS SET TRUE THEN A
17 C MINIMIZER HAS BEEN BRACKETED IN AN INTERVAL OF UNCERTAINTY
18 C WITH ENDPOINTS STX AND STY.
20 C THE SUBROUTINE STATEMENT IS
22 C SUBROUTINE MCSTEP(STX,FX,DX,STY,FY,DY,STP,FP,DP,BRACKT,
27 C STX, FX, AND DX ARE VARIABLES WHICH SPECIFY THE STEP,
28 C THE FUNCTION, AND THE DERIVATIVE AT THE BEST STEP OBTAINED
29 C SO FAR. THE DERIVATIVE MUST BE NEGATIVE IN THE DIRECTION
30 C OF THE STEP, THAT IS, DX AND STP-STX MUST HAVE OPPOSITE
31 C SIGNS. ON OUTPUT THESE PARAMETERS ARE UPDATED APPROPRIATELY.
33 C STY, FY, AND DY ARE VARIABLES WHICH SPECIFY THE STEP,
34 C THE FUNCTION, AND THE DERIVATIVE AT THE OTHER ENDPOINT OF
35 C THE INTERVAL OF UNCERTAINTY. ON OUTPUT THESE PARAMETERS ARE
36 C UPDATED APPROPRIATELY.
38 C STP, FP, AND DP ARE VARIABLES WHICH SPECIFY THE STEP,
39 C THE FUNCTION, AND THE DERIVATIVE AT THE CURRENT STEP.
40 C IF BRACKT IS SET TRUE THEN ON INPUT STP MUST BE
41 C BETWEEN STX AND STY. ON OUTPUT STP IS SET TO THE NEW STEP.
43 C BRACKT IS A LOGICAL VARIABLE WHICH SPECIFIES IF A MINIMIZER
44 C HAS BEEN BRACKETED. IF THE MINIMIZER HAS NOT BEEN BRACKETED
45 C THEN ON INPUT BRACKT MUST BE SET FALSE. IF THE MINIMIZER
46 C IS BRACKETED THEN ON OUTPUT BRACKT IS SET TRUE.
48 C STPMIN AND STPMAX ARE INPUT VARIABLES WHICH SPECIFY LOWER
49 C AND UPPER BOUNDS FOR THE STEP.
51 C INFO IS AN INTEGER OUTPUT VARIABLE SET AS FOLLOWS:
52 C IF INFO = 1,2,3,4,5, THEN THE STEP HAS BEEN COMPUTED
53 C ACCORDING TO ONE OF THE FIVE CASES BELOW. OTHERWISE
54 C INFO = 0, AND THIS INDICATES IMPROPER INPUT PARAMETERS.
58 C FORTRAN-SUPPLIED ... ABS,MAX,MIN,SQRT
60 C ARGONNE NATIONAL LABORATORY. MINPACK PROJECT. JUNE 1983
61 C JORGE J. MORE', DAVID J. THUENTE
63 DOUBLE PRECISION GAMMA
,P
,Q
,R
,S
,SGND
,STPC
,STPF
,STPQ
,THETA
66 C CHECK THE INPUT PARAMETERS FOR ERRORS.
68 IF ((BRACKT
.AND
. (STP
.LE
. MIN
(STX
,STY
) .OR
.
69 * STP
.GE
. MAX
(STX
,STY
))) .OR
.
70 * DX*
(STP
-STX
) .GE
. 0.0D0
.OR
. STPMAX
.LT
. STPMIN
) RETURN
72 C DETERMINE IF THE DERIVATIVES HAVE OPPOSITE SIGN.
74 SGND
= DP*
(DX
/DABS
(DX
))
76 C FIRST CASE. A HIGHER FUNCTION VALUE.
77 C THE MINIMUM IS BRACKETED. IF THE CUBIC STEP IS CLOSER
78 C TO STX THAN THE QUADRATIC STEP, THE CUBIC STEP IS TAKEN,
79 C ELSE THE AVERAGE OF THE CUBIC AND QUADRATIC STEPS IS TAKEN.
84 THETA
= 3*(FX
- FP
)/(STP
- STX
) + DX
+ DP
85 S
= MAX
(DABS
(THETA
),DABS
(DX
),DABS
(DP
))
86 GAMMA
= S*DSQRT
((THETA
/S
)**2 - (DX
/S
)*(DP
/S
))
87 IF (STP
.LT
. STX
) GAMMA
= -GAMMA
88 P
= (GAMMA
- DX
) + THETA
89 Q
= ((GAMMA
- DX
) + GAMMA
) + DP
91 STPC
= STX
+ R*
(STP
- STX
)
92 STPQ
= STX
+ ((DX
/((FX
-FP
)/(STP
-STX
)+DX
))/2)*(STP
- STX
)
93 IF (DABS
(STPC
-STX
) .LT
. DABS
(STPQ
-STX
)) THEN
96 STPF
= STPC
+ (STPQ
- STPC
)/2
100 C SECOND CASE. A LOWER FUNCTION VALUE AND DERIVATIVES OF
101 C OPPOSITE SIGN. THE MINIMUM IS BRACKETED. IF THE CUBIC
102 C STEP IS CLOSER TO STX THAN THE QUADRATIC (SECANT) STEP,
103 C THE CUBIC STEP IS TAKEN, ELSE THE QUADRATIC STEP IS TAKEN.
105 ELSE IF (SGND
.LT
. 0.0D0
) THEN
108 THETA
= 3*(FX
- FP
)/(STP
- STX
) + DX
+ DP
109 S
= MAX
(DABS
(THETA
),DABS
(DX
),DABS
(DP
))
110 GAMMA
= S*DSQRT
((THETA
/S
)**2 - (DX
/S
)*(DP
/S
))
111 IF (STP
.GT
. STX
) GAMMA
= -GAMMA
112 P
= (GAMMA
- DP
) + THETA
113 Q
= ((GAMMA
- DP
) + GAMMA
) + DX
115 STPC
= STP
+ R*
(STX
- STP
)
116 STPQ
= STP
+ (DP
/(DP
-DX
))*(STX
- STP
)
117 IF (DABS
(STPC
-STP
) .GT
. DABS
(STPQ
-STP
)) THEN
124 C THIRD CASE. A LOWER FUNCTION VALUE, DERIVATIVES OF THE
125 C SAME SIGN, AND THE MAGNITUDE OF THE DERIVATIVE DECREASES.
126 C THE CUBIC STEP IS ONLY USED IF THE CUBIC TENDS TO INFINITY
127 C IN THE DIRECTION OF THE STEP OR IF THE MINIMUM OF THE CUBIC
128 C IS BEYOND STP. OTHERWISE THE CUBIC STEP IS DEFINED TO BE
129 C EITHER STPMIN OR STPMAX. THE QUADRATIC (SECANT) STEP IS ALSO
130 C COMPUTED AND IF THE MINIMUM IS BRACKETED THEN THE THE STEP
131 C CLOSEST TO STX IS TAKEN, ELSE THE STEP FARTHEST AWAY IS TAKEN.
133 ELSE IF (DABS
(DP
) .LT
. DABS
(DX
)) THEN
136 THETA
= 3*(FX
- FP
)/(STP
- STX
) + DX
+ DP
137 S
= MAX
(DABS
(THETA
),DABS
(DX
),DABS
(DP
))
139 C THE CASE GAMMA = 0 ONLY ARISES IF THE CUBIC DOES NOT TEND
140 C TO INFINITY IN THE DIRECTION OF THE STEP.
142 GAMMA
= S*DSQRT
(MAX
(0.0D0
,(THETA
/S
)**2 - (DX
/S
)*(DP
/S
)))
143 IF (STP
.GT
. STX
) GAMMA
= -GAMMA
144 P
= (GAMMA
- DP
) + THETA
145 Q
= (GAMMA
+ (DX
- DP
)) + GAMMA
147 IF (R
.LT
. 0.0D0
.AND
. GAMMA
.NE
. 0.0D0
) THEN
148 STPC
= STP
+ R*
(STX
- STP
)
149 ELSE IF (STP
.GT
. STX
) THEN
154 STPQ
= STP
+ (DP
/(DP
-DX
))*(STX
- STP
)
156 IF (DABS
(STP
-STPC
) .LT
. DABS
(STP
-STPQ
)) THEN
162 IF (DABS
(STP
-STPC
) .GT
. DABS
(STP
-STPQ
)) THEN
169 C FOURTH CASE. A LOWER FUNCTION VALUE, DERIVATIVES OF THE
170 C SAME SIGN, AND THE MAGNITUDE OF THE DERIVATIVE DOES
171 C NOT DECREASE. IF THE MINIMUM IS NOT BRACKETED, THE STEP
172 C IS EITHER STPMIN OR STPMAX, ELSE THE CUBIC STEP IS TAKEN.
178 THETA
= 3*(FP
- FY
)/(STY
- STP
) + DY
+ DP
179 S
= MAX
(DABS
(THETA
),DABS
(DY
),DABS
(DP
))
180 GAMMA
= S*DSQRT
((THETA
/S
)**2 - (DY
/S
)*(DP
/S
))
181 IF (STP
.GT
. STY
) GAMMA
= -GAMMA
182 P
= (GAMMA
- DP
) + THETA
183 Q
= ((GAMMA
- DP
) + GAMMA
) + DY
185 STPC
= STP
+ R*
(STY
- STP
)
187 ELSE IF (STP
.GT
. STX
) THEN
194 C UPDATE THE INTERVAL OF UNCERTAINTY. THIS UPDATE DOES NOT
195 C DEPEND ON THE NEW STEP OR THE CASE ANALYSIS ABOVE.
202 IF (SGND
.LT
. 0.0D0
) THEN
212 C COMPUTE THE NEW STEP AND SAFEGUARD IT.
214 STPF
= MIN
(STPMAX
,STPF
)
215 STPF
= MAX
(STPMIN
,STPF
)
217 IF (BRACKT
.AND
. BOUND
) THEN
218 IF (STY
.GT
. STX
) THEN
219 STP
= MIN
(STX
+0.66D0*
(STY
-STX
),STP
)
221 STP
= MAX
(STX
+0.66D0*
(STY
-STX
),STP
)
226 C LAST LINE OF SUBROUTINE MCSTEP.