cdzro.f 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. *DECK CDZRO
  2. SUBROUTINE CDZRO (AE, F, H, N, NQ, IROOT, RE, T, YH, UROUND, B, C,
  3. 8 FB, FC, Y)
  4. C***BEGIN PROLOGUE CDZRO
  5. C***SUBSIDIARY
  6. C***PURPOSE CDZRO 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 COMPLEX (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 CDRIV 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 CDNTP
  53. C***REVISION HISTORY (YYMMDD)
  54. C 790601 DATE WRITTEN
  55. C 900329 Initial submission to SLATEC.
  56. C***END PROLOGUE CDZRO
  57. INTEGER IC, IROOT, KOUNT, N, NQ
  58. COMPLEX Y(*), YH(N,*)
  59. REAL A, ACBS, ACMB, AE, B, C, CMB, ER, F, FA, FB, FC,
  60. 8 H, P, Q, RE, RW, T, TOL, UROUND
  61. C***FIRST EXECUTABLE STATEMENT CDZRO
  62. ER = 4.E0*UROUND
  63. RW = MAX(RE, ER)
  64. IC = 0
  65. ACBS = ABS(B - C)
  66. A = C
  67. FA = FC
  68. KOUNT = 0
  69. C Perform interchange
  70. 10 IF (ABS(FC) .LT. ABS(FB)) THEN
  71. A = B
  72. FA = FB
  73. B = C
  74. FB = FC
  75. C = A
  76. FC = FA
  77. END IF
  78. CMB = 0.5E0*(C - B)
  79. ACMB = ABS(CMB)
  80. TOL = RW*ABS(B) + AE
  81. C Test stopping criterion
  82. IF (ACMB .LE. TOL) RETURN
  83. IF (KOUNT .GT. 50) RETURN
  84. C Calculate new iterate implicitly as
  85. C B + P/Q, where we arrange P .GE. 0.
  86. C The implicit form is used to prevent overflow.
  87. P = (B - A)*FB
  88. Q = FA - FB
  89. IF (P .LT. 0.E0) THEN
  90. P = -P
  91. Q = -Q
  92. END IF
  93. C Update A and check for satisfactory reduction
  94. C in the size of our bounding interval.
  95. A = B
  96. FA = FB
  97. IC = IC + 1
  98. IF (IC .GE. 4) THEN
  99. IF (8.E0*ACMB .GE. ACBS) THEN
  100. C Bisect
  101. B = 0.5E0*(C + B)
  102. GO TO 20
  103. END IF
  104. IC = 0
  105. END IF
  106. ACBS = ACMB
  107. C Test for too small a change
  108. IF (P .LE. ABS(Q)*TOL) THEN
  109. C Increment by tolerance
  110. B = B + SIGN(TOL, CMB)
  111. C Root ought to be between
  112. C B and (C + B)/2.
  113. ELSE IF (P .LT. CMB*Q) THEN
  114. C Interpolate
  115. B = B + P/Q
  116. ELSE
  117. C Bisect
  118. B = 0.5E0*(C + B)
  119. END IF
  120. C Have completed computation
  121. C for new iterate B.
  122. 20 CALL CDNTP (H, 0, N, NQ, T, B, YH, Y)
  123. FB = F(N, B, Y, IROOT)
  124. IF (N .EQ. 0) RETURN
  125. IF (FB .EQ. 0.E0) RETURN
  126. KOUNT = KOUNT + 1
  127. C
  128. C Decide whether next step is interpolation or extrapolation
  129. C
  130. IF (SIGN(1.0E0, FB) .EQ. SIGN(1.0E0, FC)) THEN
  131. C = A
  132. FC = FA
  133. END IF
  134. GO TO 10
  135. END