-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmnbrak.f
61 lines (61 loc) · 1.3 KB
/
mnbrak.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
SUBROUTINE MNBRAK(AX,BX,CX,FA,FB,FC,FUNC)
PARAMETER (GOLD=1.618034, GLIMIT=100., TINY=1.E-20)
FA=FUNC(AX)
FB=FUNC(BX)
IF(FB.GT.FA)THEN
DUM=AX
AX=BX
BX=DUM
DUM=FB
FB=FA
FA=DUM
ENDIF
CX=BX+GOLD*(BX-AX)
FC=FUNC(CX)
1 IF(FB.GE.FC)THEN
R=(BX-AX)*(FB-FC)
Q=(BX-CX)*(FB-FA)
U=BX-((BX-CX)*Q-(BX-AX)*R)/(2.*SIGN(MAX(ABS(Q-R),TINY),Q-R))
ULIM=BX+GLIMIT*(CX-BX)
IF((BX-U)*(U-CX).GT.0.)THEN
FU=FUNC(U)
IF(FU.LT.FC)THEN
AX=BX
FA=FB
BX=U
FB=FU
GO TO 1
ELSE IF(FU.GT.FB)THEN
CX=U
FC=FU
GO TO 1
ENDIF
U=CX+GOLD*(CX-BX)
FU=FUNC(U)
ELSE IF((CX-U)*(U-ULIM).GT.0.)THEN
FU=FUNC(U)
IF(FU.LT.FC)THEN
BX=CX
CX=U
U=CX+GOLD*(CX-BX)
FB=FC
FC=FU
FU=FUNC(U)
ENDIF
ELSE IF((U-ULIM)*(ULIM-CX).GE.0.)THEN
U=ULIM
FU=FUNC(U)
ELSE
U=CX+GOLD*(CX-BX)
FU=FUNC(U)
ENDIF
AX=BX
BX=CX
CX=U
FA=FB
FB=FC
FC=FU
GO TO 1
ENDIF
RETURN
END