2D AMRCLAW
zeroin.f
Go to the documentation of this file.
1 c
2 c
3 c
4 c =================================================
5  function zeroin(ax,bx,f,tol)
6 c =================================================
7  implicit double precision (a-h,o-z)
8  external f
9 c
10 c a zero of the function f(x) is computed in the interval ax,bx .
11 c (Standard routine from netlib)
12 c
13 c input..
14 c
15 c ax left endpoint of initial interval
16 c bx right endpoint of initial interval
17 c f function subprogram which evaluates f(x) for any x in
18 c the interval ax,bx
19 c tol desired length of the interval of uncertainty of the
20 c final result ( .ge. 0.d0)
21 c
22 c
23 c output..
24 c
25 c zeroin abcissa approximating a zero of f in the interval ax,bx
26 c
27 c
28 c it is assumed that f(ax) and f(bx) have opposite signs
29 c without a check. zeroin returns a zero x in the given interval
30 c ax,bx to within a tolerance 4*macheps*dabs(x) + tol, where macheps
31 c is the relative machine precision.
32 c
33 c this function subprogram is a slightly modified translation of
34 c the algol 60 procedure zero given in richard brent, algorithms for
35 c minimization without derivatives, prentice - hall, inc. (1973).
36 c
37 c
38 c
39 c compute eps, the relative machine precision
40 c
41  eps = 1.d0
42  10 eps = eps/2.d0
43  tol1 = 1.d0 + eps
44  if (tol1 .gt. 1.d0) go to 10
45 c
46 c initialization
47 c
48  a = ax
49  b = bx
50  fa = f(a)
51  fb = f(b)
52 c
53 c begin step
54 c
55  20 c = a
56  fc = fa
57  d = b - a
58  e = d
59  30 if (dabs(fc) .ge. dabs(fb)) go to 40
60  a = b
61  b = c
62  c = a
63  fa = fb
64  fb = fc
65  fc = fa
66 c
67 c convergence test
68 c
69  40 tol1 = 2.d0*eps*dabs(b) + 0.5*tol
70  xm = .5*(c - b)
71  if (dabs(xm) .le. tol1) go to 90
72  if (fb .eq. 0.d0) go to 90
73 c
74 c is bisection necessary
75 c
76  if (dabs(e) .lt. tol1) go to 70
77  if (dabs(fa) .le. dabs(fb)) go to 70
78 c
79 c is quadratic interpolation possible
80 c
81  if (a .ne. c) go to 50
82 c
83 c linear interpolation
84 c
85  s = fb/fa
86  p = 2.d0*xm*s
87  q = 1.d0 - s
88  go to 60
89 c
90 c inverse quadratic interpolation
91 c
92  50 q = fa/fc
93  r = fb/fc
94  s = fb/fa
95  p = s*(2.d0*xm*q*(q - r) - (b - a)*(r - 1.d0))
96  q = (q - 1.d0)*(r - 1.d0)*(s - 1.d0)
97 c
98 c adjust signs
99 c
100  60 if (p .gt. 0.d0) q = -q
101  p = dabs(p)
102 c
103 c is interpolation acceptable
104 c
105  if ((2.d0*p) .ge. (3.d0*xm*q - dabs(tol1*q))) go to 70
106  if (p .ge. dabs(0.5*e*q)) go to 70
107  e = d
108  d = p/q
109  go to 80
110 c
111 c bisection
112 c
113  70 d = xm
114  e = d
115 c
116 c complete step
117 c
118  80 a = b
119  fa = fb
120  if (dabs(d) .gt. tol1) b = b + d
121  if (dabs(d) .le. tol1) b = b + dsign(tol1, xm)
122  fb = f(b)
123  if ((fb*(fc/dabs(fc))) .gt. 0.d0) go to 20
124  go to 30
125 c
126 c done
127 c
128  90 zeroin = b
129  return
130  end
function zeroin(ax, bx, f, tol)
Definition: zeroin.f:6