sdzro.f 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. *DECK SDZRO
  2. SUBROUTINE SDZRO (AE, F, H, N, NQ, IROOT, RE, T, YH, UROUND, B, C,
  3. 8 FB, FC, Y)
  4. C***BEGIN PROLOGUE SDZRO
  5. C***SUBSIDIARY
  6. C***PURPOSE SDZRO searches for a zero of a function F(N, T, Y, IROOT)
  7. C between the given values B and C until the width of the
  8. C interval (B, C) has collapsed to within a tolerance
  9. C specified by the stopping criterion,
  10. C ABS(B - C) .LE. 2.*(RW*ABS(B) + AE).
  11. C***LIBRARY SLATEC (SDRIVE)
  12. C***TYPE SINGLE PRECISION (SDZRO-S, DDZRO-D, CDZRO-C)
  13. C***AUTHOR Kahaner, D. K., (NIST)
  14. C National Institute of Standards and Technology
  15. C Gaithersburg, MD 20899
  16. C Sutherland, C. D., (LANL)
  17. C Mail Stop D466
  18. C Los Alamos National Laboratory
  19. C Los Alamos, NM 87545
  20. C***DESCRIPTION
  21. C
  22. C This is a special purpose version of ZEROIN, modified for use with
  23. C the SDRIV package.
  24. C
  25. C Sandia Mathematical Program Library
  26. C Mathematical Computing Services Division 5422
  27. C Sandia Laboratories
  28. C P. O. Box 5800
  29. C Albuquerque, New Mexico 87115
  30. C Control Data 6600 Version 4.5, 1 November 1971
  31. C
  32. C PARAMETERS
  33. C F - Name of the external function, which returns a
  34. C real result. This name must be in an
  35. C EXTERNAL statement in the calling program.
  36. C B - One end of the interval (B, C). The value returned for
  37. C B usually is the better approximation to a zero of F.
  38. C C - The other end of the interval (B, C).
  39. C RE - Relative error used for RW in the stopping criterion.
  40. C If the requested RE is less than machine precision,
  41. C then RW is set to approximately machine precision.
  42. C AE - Absolute error used in the stopping criterion. If the
  43. C given interval (B, C) contains the origin, then a
  44. C nonzero value should be chosen for AE.
  45. C
  46. C***REFERENCES L. F. Shampine and H. A. Watts, ZEROIN, a root-solving
  47. C routine, SC-TM-70-631, Sept 1970.
  48. C T. J. Dekker, Finding a zero by means of successive
  49. C linear interpolation, Constructive Aspects of the
  50. C Fundamental Theorem of Algebra, edited by B. Dejon
  51. C and P. Henrici, 1969.
  52. C***ROUTINES CALLED SDNTP
  53. C***REVISION HISTORY (YYMMDD)
  54. C 790601 DATE WRITTEN
  55. C 900329 Initial submission to SLATEC.
  56. C***END PROLOGUE SDZRO
  57. INTEGER IC, IROOT, KOUNT, N, NQ
  58. REAL A, ACBS, ACMB, AE, B, C, CMB, ER, F, FA, FB, FC,
  59. 8 H, P, Q, RE, RW, T, TOL, UROUND, Y(*), YH(N,*)
  60. C***FIRST EXECUTABLE STATEMENT SDZRO
  61. ER = 4.E0*UROUND
  62. RW = MAX(RE, ER)
  63. IC = 0
  64. ACBS = ABS(B - C)
  65. A = C
  66. FA = FC
  67. KOUNT = 0
  68. C Perform interchange
  69. 10 IF (ABS(FC) .LT. ABS(FB)) THEN
  70. A = B
  71. FA = FB
  72. B = C
  73. FB = FC
  74. C = A
  75. FC = FA
  76. END IF
  77. CMB = 0.5E0*(C - B)
  78. ACMB = ABS(CMB)
  79. TOL = RW*ABS(B) + AE
  80. C Test stopping criterion
  81. IF (ACMB .LE. TOL) RETURN
  82. IF (KOUNT .GT. 50) RETURN
  83. C Calculate new iterate implicitly as
  84. C B + P/Q, where we arrange P .GE. 0.
  85. C The implicit form is used to prevent overflow.
  86. P = (B - A)*FB
  87. Q = FA - FB
  88. IF (P .LT. 0.E0) THEN
  89. P = -P
  90. Q = -Q
  91. END IF
  92. C Update A and check for satisfactory reduction
  93. C in the size of our bounding interval.
  94. A = B
  95. FA = FB
  96. IC = IC + 1
  97. IF (IC .GE. 4) THEN
  98. IF (8.E0*ACMB .GE. ACBS) THEN
  99. C Bisect
  100. B = 0.5E0*(C + B)
  101. GO TO 20
  102. END IF
  103. IC = 0
  104. END IF
  105. ACBS = ACMB
  106. C Test for too small a change
  107. IF (P .LE. ABS(Q)*TOL) THEN
  108. C Increment by tolerance
  109. B = B + SIGN(TOL, CMB)
  110. C Root ought to be between
  111. C B and (C + B)/2.
  112. ELSE IF (P .LT. CMB*Q) THEN
  113. C Interpolate
  114. B = B + P/Q
  115. ELSE
  116. C Bisect
  117. B = 0.5E0*(C + B)
  118. END IF
  119. C Have completed computation
  120. C for new iterate B.
  121. 20 CALL SDNTP (H, 0, N, NQ, T, B, YH, Y)
  122. FB = F(N, B, Y, IROOT)
  123. IF (N .EQ. 0) RETURN
  124. IF (FB .EQ. 0.E0) RETURN
  125. KOUNT = KOUNT + 1
  126. C
  127. C Decide whether next step is interpolation or extrapolation
  128. C
  129. IF (SIGN(1.0E0, FB) .EQ. SIGN(1.0E0, FC)) THEN
  130. C = A
  131. FC = FA
  132. END IF
  133. GO TO 10
  134. END