Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ALGORITHM 012

A Fortran program for solving a nonlinear equation by Muller's


method
I. B a r r o d a l e a n d K. B. Wilson (*)

ABSTRACT

C o m p u t a t i o n a l e x p e r i e n c e w i t h Muller's m e t h o d indicates t h a t it is a v e r y e f f i c i e n t a l g o r i t h m for


c o m p u t i n g real, c o m p l e x , a n d multiple zeros o f a r b i t r a r y f u n c t i o n s . F u r t h e r m o r e , it does n o t
require a c c u r a t e initial e s t i m a t e s o f the zeros, n o r does it r e q u i r e t h e e v a l u a t i o n o f the derivative
o f the f u n c t i o n . We p r e s e n t a F o r t r a n p r o g r a m for Muller's m e t h o d a n d , using n u m e r i c a l e x a m p l e s ,
we c o m p a r e its e f f i c i e n c y t o t h a t o f a g o o d b r a c k e t i n g algorithm.

1. INTRODUCTION zeros, and real zeros of even multiplicity). We there-


fore present a Fortran program based on the concise
Nerinckx and Haegemans [4] recently presented a formulation of Muller's method given by Traub [5]
comparative study of ten programs for calculating in 1964.
a real root of a nonlinear equation with one un-
known, without using derivatives. All of the pro-
grams require as input the endpoints of a real inter- 2. MULLER'S METHOD
val which contains the desired zero, and a tolerance
e. The output is an interval of length less than 2e Let x 1, x 2, and x 3 be successive estimates of a zero
containing a zero, or a value approximating a zero of a given function f(x), where x 3 denotes the newest
to within the tolerance e. Based on the number of estimate and x I is the oldest estimate. Each iteration
function evaluations needed by the various algorithms
of Muller's method produces a new estimate ~" by
to £md zeros of several test functions, the authors
calculating the nearer zero to x 3 of the quadratic
conclude that the best results are given by the 1975
polynomial q (x) which satisfies
algorithm ZEROINRAT of Bus and Dekker [1].
While conceding that algorithms which always bracket q ( x i ) = f(xi) for i = 1, 2, and 3,
the desired zero have the advantage of guaranteed
convergence, we wish to draw attention to the fact and then setting x I = x 2, x 2 = x 3, and x 3 = ~. The
that far less restrictive algorithms are available which iterations are continued until the successive values of
are of comparable efficiency to, say, ZEROINRAT. converge or until k iterations have been completed,
Indeed, our experience with the 1956 method of where k is the maximum number of iterations allowed.
successive quadratic interpolation due to Muller [31 The main algorithmic details are as follows.
has been very satisfactory, and the numerical results Muller's method requires as input x i and yi[= f(xi) ]
in Section 4 show that it often requires fewer func- for i = 1, 2, and 3, and then each iteration consists
tion evaluations than ZEROINRAT when applied to of two steps :
a selection of the test functions used in [4]. Further-
(i) ~ ,-, x 3 - 2y 3 / (b -+ X/b2 - 4aY3).
more, Muller's method is very effective in locating
multiple zeros and complex zeros, and it can be used [The denominator of larger magnitude is chosen,
to fred several roots of a given equation without thus ensuring that • is the closer root to x 3. If
requiring accurate initial estimates of its roots. the value of the denominator is 0, ~ is assigned
Thus, the purpose of this paper is not to suggest the (arbitrary) value 2x 3 - x 2 in order to proceed
that Muller's method (which may converge to a zero (see Muller [317.1
outside a desired interval) is superior to ZEROINRAT,
but rather to demonstrate its efficiency, and also to (ii) x 1 . - x 2 , Yl~Y2'X2"-x3'Y2+-Y3'X3*- ~'
illustrate its effectiveness in situations where bracket-
ing algorithms cannot be used (Le. locating complex
Y3 *- f(~)"

(*) I. Barrodale a n d K. B. Wilson, D e p a r t m e n t o f Mathematics, U n i v e r s i t y o f Victoria, V i c t o r i a ,


B. C., Canada.

Journal of Computational and Applied Mathematics, volume 4, no 2, 1978. 159


The coefficients a and b in step (i) are conveniently variable REALRT is given the value TRUE if only
expressed in terms of divided differences as real roots are desired, and the value FALSE if com-
plex roots are desired.
a= f[x 3'x 2,xl] andb= f [ x 3 , x 2 ] + ( x 3 - x 2 ) a. The real numbers EP1 and EP2 are small positive
tolerances used to test for convergence, as follows :
Hence each iteration requires one new function
evaluation Y3' and the new coefficients a and b are
if I~=x31 < EP1 [-fl or If(x--)[ < EP2
calculated using Y3 together with information avail-
able from the previous iteration.
then ~ is a root of f (x) = 0.
Convergence of Muller's method can be shown to
occur under certain conditions, although no general EP2 is also used to determine ff the new estimate is
proof of convergence is available : the order of con- dose to a root which is already known. Thus, if a is
vergence is 1.84 for a simple zero and 1.23 for a a known root and ~ is a current estimate of a root,
double zero (see Muller [3] or Traub [5] for details). then if IT - al • EP2 we perturb ~ slightly and con-
Although our program has sometimes converged to tinue the iterations. Empirical evidence suggests setting
a different zero than the one we were seeking, it has EP1 = 10 -3d/4 and EP2 = 10 -d + 1 , where d repre-
always converged in practice even from poor initial
sents the number of decimal digits of accuracy avifil-
estimates. However, it does include a device (similar
able. However, when calculating multiple zeros EP1
to one due to Muller) which adjusts the new esti-
might be set to a larger value dependent on the
mate ~, by successive halving of the step size (x 3 - ~ ) ,
multiplicity of the zeros.
whenever divergence is detected (Le. if
The integer GUESS represents the number of new
[f(x-)l • 100 If(x3)l ).
roots for which the user is supplying estimates.
A further feature of Muller's method is that it can MAXITS is an integer which specifies the maximum
locate real or complex zeros; it can also converge to number of function evaluations (iterations) permitted
a complex zero starting from real initial estimates. in calculating any one root, including the three initial
The program presented in the next section is written evaluations.
in the complex mode, so typically it produces real RTS is a complex vector with at least KM components.
zeros as complex numbers with small imaginary com- On entry, RTS must contain the known roots as its
ponents. However, the program can be directed to first KNOWN components and the estimates of the
determine real zeros only, and then it produces com- desired roots as its next GUESS components. On exit,
plex numbers with zero imaginary components. This RTS supplies all the roots which are currently known
is accomplished by setting the square root term in as its first NFOUND components and, if a root has
step (i) to zero whenever the quantity b 2 - 4 a y ~ i s caused the method to "fail" by requiring more than
negative; this strategy is equivalent to applying the MAXITS iterations, the (NFOUND + 1)th. component
"double zero" version of the Newton-gaphson gives the last estimate of that root. NFOUND is an
method to the quadratic q (x). integer denoting the number of roots available on
In addition, when computing real zeros our program exit. FNV is a complex vector of dimension at least
tries to ensure that i is on the "downhill" side o f KM whose leading components give the function
x3; this is accomplished by changing the subtraction values associated with the values stored in RTS.
in step (i) to an addition, when required (for further Finally, IFAIL is an integer exit code with the follow-
details see the section of code between statement ing values :
numbers 100 and 110)(*).
0 - indicates that NMORE new roots were found as
requested, and all the known roots supplied by
the user have function values less than EP2 in
3. SUBPROGRAM ROOTS : DESCRIPTION AND
modulus,
USAGE
1 - indicates that NMORE new roots were found, but
in addition some of the known roots were recal-
The Fortran subprogram ROOTS implements in com-
culated since their o/iginal function values were
plex arithmetic the method described in Section 2
for calculating roots of f(x) = 0, although it includes
tOO large,
2 - indicates that the input values of KNOWN or
additional algorithmic refinements to handle con-
NMORE are invalid (i. e. KNOWN < 0 or
vergence and stability satisfactorily.
The integers KNOWN and NMORE represent, respec- NMORE • 0),
3 - indicates that convergence has not occurred after
tively, the number of roots already known and the
MAXITS function evaluations.
number o f new roots to be determined. K M is an
integer used for adjustable dimensions, which must In the cases 2 and 3 above premature termination
be set to at least KNOWN + b/MORE. The logical occurs immediately, and the value of NFOUND is
less than KNOWN + NMORE.
The companion subprogram TEST is used by ROOTS
(*) This modification, which was suggested to us by Mr. C. D. in two w a y s Firstly, TEST allows more than one
Mclntosh, increases the efficiency of Muller's method near root to be found by deflating the current function
"fiat" regions of f(x), e.g. when f(x) has muhiple zeros.

Journal of Computational and Applied Mathematics, volume 4, no 2, 1978. 160


value. Thus, if a 1, a,2 . . . . . a m are zeros of f(x) that test function for multiple zeros, and our program
have already been identified, when calculating the produced each zero to a relative accuracy of about
(m + l ) t h . zero TEST supplies function values to EP1 l / m , where m is the multiplicity. Apart from
ROOTS in the form function number 6, for each test function the
program was directed to determine only real zeros.
f (x) *- {... [(f (x) I (x - al) ] / (x- a2) I... / (x - am) }.
Table 1. Test functions
If f ( x ) i s a polynomial function, the user may prefer
to factor out the known zeros using synthetic divi-
sion, in which case TEST has to be modified ac- Function Interval
cordingly.
Secondly, TEST is used to check whether a current 1. f(x)- (x-1)(x-2) (x-3) a. [0, 1.5]
estimate ~ o f a zero is close to any previous zero (x-4)(x-S)(x-6) b. [1.1, 2.5]
a l , a 2 , ..., a m. Thus, if I ~ - ajl g EP2, for c. [2.1, 3.51
j = 1, 2, . . . , m, ~ is altered by setting x -- x + .01. d. [3.1, 4.5]
In practice this device does not prevent convergence e. [4.1, 5.5]
to multiple zeros.
Finally, the .user must supply a subprogram CALCF
f. [5.1, 6.5]
which evaluates f (x) for a given value of x.
2. f ( x ) = x - e -X [o, 1]
3. f(x)= sin x - . 5 [o, 1.5]
4. NUMERICAL RESULTS 4. f ( x ) = 2 x e -4 + 1 - 2e - 4 x [0, 11
5. f(x)= tan x - l . 0 1 x [.01, .71
In this section we present i~e examples selected
from [4], together.with an example involving com-
plex zeros and another example involving multiple 6. f ( x ) = x 6 - 3 x 5 + 5--x4 Calcuhte all
zeros Table 1 lists the functions f (x) and, for the 2 real and com-
Five examples from [4], their intervals of interest : lx2 + 1 plex zeros
each interval contains exacfly one real zero. 2 42
Table 2 gives the number of function evaluations
(including the three initial evaluations) required for 7. f ( x ) = ( x - . 1 ) 4 ( x - . 2 ) 3 ( x - . 3 ) 2 ( x - . 4 ) Calculate all
our program to converge. The information in Table
ten zeros
2 was obtained using three different sets of initial
estimates x 1, x 2, and x 3. Column 1 refers to the
case where x I and x 2 are the endpoints of the These results were obtained using double precision
intervals given in Table 1 and x 3 = (x I + x2) / 2, in arithmetic (approximately 16 decimal digits) on an
column 2 x 3 has the same value as in column 1 IBM 370/158 using EP1 = 10 - 1 2 and EP2= 10 -15.
while x I = x 3 - . 5 and x 2 = x 3 + . 5 (our program The results given in [ 4] were also obtained in this
assigns values to x I and x 2 in this manner whenever manner, but with a single termination criterion corre-
the user supplies an estimate x 3 of a zero), and in sponding to EP2 = 10 - I 2 . Hence, the number of func-
tion evaluations for Z E R O I N R A T shown in the last
column 3 we have x I = - .5, x 2 = .5 and x 3 = 0
column of Table 2 (which are taken from [4]) would
(which are the starting values used by our program
whenever the user does not supply initial estimates). increase slightly if EP2 is reset to 10-15).
The results in Table 2 show dearly that Muller's
For function number 1 the program was used with
method is as efficient as a good bracketing algorithm,
and without deflation for the first two sets of initial
and that even when it is started from arbitrary initial
estimates, whereas for the third set deflation has to
estimates it can locate complex zeros and multiple
be used (otherwise the program repeatedly produces
zeros within a reasonable number of function evalua-
the zero (= 1) closest to the initial estimates). The
tions.
functions numbered 2, 3 and 4 do not require defla-
There are several coded implementations Of Muller's
tion, but in column 3 function number 5 has to be
method available in subroutine libraries and in the
deflated in order to locate the desired zero (other-
literature, but we are not aware of any other code
wise the program produces the root at 0).
which fonows Traub's description. Consequently, we
Function number 6 is a Bernoulli polynomial whose
feel that our code is more readable (at least for hu-
zeros (two real and four complex) are symmetric
mans) than previous implementations, although one
about 1/2, although this property was not used in
such implementation (Conte and de Boor [2, pp. 7%
the computation (*). Function number 7 is a standard
79]) was of particular assistance to us in deciding
upon convergence criteria.
(*) However, information of this type can be used effectively Finally, since some Fortran compilers do not provide
via successive calls of our program, in which initial esti- built-in functions which extract the real and imaginary
mates of remaining zeros are formed from previously
calculated zeros.
Journal of Computational and Applied Mathematics, volume 4, no 2, 1978. 161
Table 2. Number o f function evaluations required b y Muller's method

Col. 1 Col. 2 Col. 3


<:
Endpoints and M i d p o i n t and
Z
Midpoint Midpoint + . 5 -.5, 0, .5 ©
Fn#
Defln. No Defln. Defln, No Defln. Defln. No Defln. N

1 a. 10 10 10 10 11 12
b. 9 9 9 8 11 9
C. 9 9 9 9 5 10
d. 9 9 9 9 13 11
e. 5 8 4 8 5 11
f. 4 10 5 9 17 11
2 7 7 7
3 8 8 9
4 11 9 10
5 11 11 (4 + 9) (*) 13
6(**) 10, 11, 11,
8,5,5
7(**) 11, 12, 9,
10, 13, 9,
14, 8, 6,
6

(*) Muller's method first found the root at 0.


(**) For these functions the numbers of evaluations shown are in the order in which the zeros were produced.

parts o f a double precision complex number, for REFERENCES


the convenience o f users who wish to convert our
program to double precision we provide the follow- 1. BUS, J. C. P. and DEKKER, T. J. : "Two efficient
algorithms with guaranteed convergence for finding a
ing function subprogram which performs these opera-
zero of a function", Report NW 13/75, Mathematisch
tions. Centrum Amsterdam, 1975.
FUNCTION DREAL$SIX)
2. CONTE, S. D. and DE BOOR, C. : Elementary Numerical
CQMPLE X4,16 XoDX Analysis 2nd edition, McGraw-HiU, 1972.
-

REAL~8 DIMAGtOV(2)
EQUIVALENCE IDXoDV{ 1) }
3. MULLER, D. E. : "A method of solving algebraic equa-
tions using an automatic computer", MTAC, 1__00,208-
DX = X 215, 1956.
DREAL = 0VII )
RETURN 4.
NERINCKX, D. and HAEGEMANS, A. : "A comparison
of non-linear equation solvers", J. of Comp. and App.
ENTRY DIMAG(X ) Math., 1_ 145-148, 1975.
DX = X
5. TRAUB, J. F. : Iterative Methods for the Solution of
OIMAX = DV(2) Equations, Prentice-Haft, 1964.
RETURN
END

ACKNOWLEDGEMENTS

We wish to thank Professor L. M. Delves for his con-


structive criticisms o f an earlier version o f this report,
and the fzrst-named author gratefully acknowledges
the Financial assistance provided b y NRC Grant No.
A5251.

Journal o f Computational and Applied Mathematics, volume 4, no 2, 1978. 162


SUBROUTINE ROOTS(KNOWN, NMORE, KM, REALRT, E P 1 , EP2, RO0 I0
GUESS, MAXITS, RTS, NFOUND~ FNV, I F A I L ) RO0 20
C . . . . . . " RO0 30
C THE USER MUST SUPPLY A SUBPROGRAM AS FOLLOWS: RO0 40
C RO0 50
C RO0 60
C SUBROUTINE CALCF ( X , F ) RO0 70
C RO0 80
C R00 90
C WHERE X AND F ARE COMPLEX NUMBERS, X I S AN INDEPENDENT RO0 100
C VARIABLE AND F I S THE CORRESPONDING FUNCTION VALUE. ROO 110
C RO0 120
C RO0 130
C . . . . . . . . . . . . . . . . . . . . . R00 140
C THIS SUBROUTINE USES MULLER'S METHOD TO FIND ROOTS (REAL RO0 150
C OR COMPLEX)OF A GENERAL EQUATION. RO0 160
C RO0 170
C DESCRIPTION OF PARAMETERS: RO0 180
C RO0 190
C KNOWN AN INTEGER DENOTING THE NUMBER OF ROOTS ALREADY ROO 200
C KNOWN. I F THE FUNCTION VALUE FOR ONE OF THESE RO0 210
C "KNOWN" ROOTS IS NOT "SMALL" THE VALUE OF KNOWN ROO 220
C IS RESET TO THE LAST INDEX OF A ROOT WITH A SMALL RO0 230
C FUNCTION VALUE, AND THE REMAINING 'KNOWN" ROOTS RO0 240
C ARE RECALCULATED. RO0 250
C NMORE AN INTEGER DENOTING THE NUMBER OF ROOTS TO BE FOUND RO0 260
C (I.E. IN ADDITION TO THOSE ALREADY KNOWN)* NMORE RO0 270
C I S RESET TO ACCOUNT FOR THE CASE WHEN KNOWN I S ROD 280
C RESET. ROO 290
C KM AN ~NTEGER USED TO DEFINE DIMENSIONS. KM MUST BE RO0 300
C SET TO AT LEAST (KNOWN+NHORE). ROO 310
C REALRT A. LQGICAL VARIABLE WITH VALUES AS FOLLOWSS ROO 320
C .TRUE. INDICATES THAT ONLY REAL ROOTS ( I , E . RO0 330
C COMPLEX NUMBERS WITH ZERO IMAGINARY PARTS) ARE RO0 340
C TO BE FOUND. RO0 350
C . F A L S E . INDICATES THAT COMPLEX ROOTS ARE TO RO0 360
C BE FOUND. RO0 370
C EP1 A SMALL P O S I T I V E REAL NUMBER DENOTING THE RO0 380
C " F I R S T " CONVERGENCE CRITERIONS RO0 390
C I F AT THE K~TH STAGE THE RELATIVE CHANGE IN TWO RO0 400
C SUCCESSIVE APPROXIMATIONS TO A ROOT I S LESS THAN RO0 410
C E P 1 , CONVERGENCE I S SAID TO HAVE TAKEN PLACE ( I . E . RO0 420
C I F THE ABSOLUTE VALUE OF ( ( R O O T ( K ) - R O O T ( K - 1 ) ) / R O O T ( K ) RO0 430
C I S LESS THAN EP1 THEN CONVERGENCE OCCURS). RO0 440
C SEE BELOW FOR MINIMUM DEFAULT VALUES. ROO 450
C EP2 A SMALL P O S I T I V E REAL NUMBER DENOTING THE RO0 460
C "SECOND" CONVERGENCE CRITERIONS ROO 470
C I F AT ANY STAGE THE ABSOLUTE VALUE OF THE FUNCTION RO0 480
C I S LESS THAN E P 2 , CONVERGENCE I S SAID TO HAVE RO0 490
C TAKEN PLACE, RO0 500
C SEE BELOW FOR MINIMUM DEFAULT VALUES. RO0 510
C EP2 I S ALSO USED BY SUBROUTINE TEST TO RO0 520
C • DETERMINE I F A CURRENT APPROXIMATION I S "CLOSE' RO0 530
C TO A ROOT ALREADY I D E N T I F I E D . RO0 540
C GUESS AN INTEGER DENOTING THE NUMBER OF ROOTS FOR WHICH ROO 550
C THE USER I S SUPPLYING ESTIMATES. GUESS I S RESET RO0 560
C TO ACCOUNT FOR THE CASE WHEN KNOWN I S RO0 570
C RESET. ALSO, GUESS MUST NOT EXCEED NMORE. RO0 580
C MAXITS AR INTEGER DENOTING THE MAXIMUM NUMBER OF RO0 590
C FUNCTION CALLS ALLOWED WHEN FINDING ANY ROOT. ROO 600
C I F MAXITS FUNCTION EVALUATIONS ARE PERFORMED THE RO0 610
C SUBROUTINE " F A I L S " AND RETURNS CONTROL TO THE ROO 620
C USER. THE ROOTS ALREADY FOUND AND THE LAST RO0 630
C APPROXIMATION TO THE ROOT CAUSING " F A I L U R E " ARE RO0 640
C STORED I N RTS. ROO 650
C SEE BELOW FOR HAXIMUH DEFAULT VALUES, RO0 660
CRTS A COMPLEX VECTOR OF LENGTH AT LEAST KMS ROO 670
RO0 680
C
C ON ENTRY I F ANY ROOTS ARE AVAILABLE THEY MUST BE RO0 690
C IN POSITIONS ONE TO KNOWN OF RTS. RO0 700
RO0 710
C

Journal o f Computational and Applied Mathematics, volume 4, no 2, 1978. 163


C ON ENTRY I F E S T I M A T E S OF THE ROOTS TO BE FOUND ARE RO0 720
C KNOWN ( I . E . OUESS.GT.ZERO) THEY MUST BE IN RO0 730
C P O S I T I O N S (KNOWN+l) TO ( K N O W N + G U E S S ) . RO0 740
C RO0 750
C ON RETURN THE ROOTS OF THE EQUATION ARE STORED IN RO0 760
C THE F I R S T NFGUND P O S I T I O N S . I F " F A I L U R E ' DUE TO RO0 770
C MAXITS CAUSES RETURN, THE ( N F O U N D + I ) P O S I T I O N OF RO0 780
C RTS CONTAINS THE LAST A P P R O X I M A T I O N TO THE ROOT RO0 790
C WHICH CAUSED THE " F A I L U R E ' . ROO 800
C ROO BlO
C NFOUND AN INTEGER DENOTING THE NUMBER OF ROOTS NOW KNOWN RO0 820
C AND STORED I N R T S . RO0 830
C FNV A COMPLEX VECTOR OF LENGTH AT LEAST KM CONTAINING RO0 840
C THE FUNCTION VALUES A S S O C I A T E D WITH THE VECTOR R T S . RO0 850
C RO0 860
C IFAIL AN INTEGER E X I T CODE WITH VALUES AS FOLLOWS: RO0 870
0 I N D I C A T E S ALL ROOTS WERE FOUND AS REQUESTED RO0 880
BY THE U S E R , RO0 890
1 I N D I C A T E S ( A S ABOVE) ALL ROOTS WERE FOUND RO0 900
BUT I N A D D I T I O N SOME OF THE INPUT "KNOWN" RO0 910
ROOTS WERE RECALCULATED, RO0 920
2 I F THE INPUT PARAMETERS KNOWN OR NMORE RO0 930
S A T I S F Y THE FOLLOWING, RO0 940
RO0 950
KNOWN.LT.O RO0 960
NMORE.LT.1 RO0 970
RO0 980
CONTROL I S RETURNED IMMEDIATELY TO THE U S E R , RO0 990
3 I F MAXITS CAUSES " F A I L U R E " CONTROL I S ROO IO00
RETURNED IMMEDIATELY TO THE USER. RO0 IO10
RO0 1020
COMPLEX RTS(KM), FNV(KM), X l , X2, X3, F 1 , F2 , F3, ROO 1030
X 2 1 , X32, F 2 1 , F 3 2 , F 3 1 , F 3 2 1 , B, XNEW, FNEW, DENOM, RO0 1040
FSAVE, CSQRT, RADICL, RT, D I F , CSTEP, FSLAST RO0 1050
REAL EP1, EP2, ONE, HUNDRD, TWO, FOUR, HALF, STEP, RO0 1060
ZERO, EPIDEF, EP2DEF RO0 1070
INTEGER GUESS RO0 1080
LOGICAL REALRT .RO0 1090
DATA IZERO, IONE, ITWO, ITHREE, ZERO, HALF, ONE, TWO, RO0 1100
FOUR, HUNDRD, ITSDEF, EPIDEF, EP2DEF RO0 1110
/0,1,213,0.OEO,Oo5EO,loOEO,2.0EO,4.0EO,100.OEO,100, RO0 1120
0.5E-5,1.0E-6/ RO0 1130
C RO0 1140
C INITIALIZATION. RO0 1150
C CHECK FOR ERRORS IN THE I N P U T AND SET DEFAULT VALUES I F RO0 1160
C NECESSARY. RO0 1170
C RO0 1180
EP1 = A M A X I ( E P 1 , E P I D E F ) RO0 1190
EP2 = AMAXI(EP2,EP2DEF) RO0 1200
MAXITS = M I N O ( M A X I T S , I T S D E F ) RO0 1210
I F A I L = IZERO RO0 1220
NFOUND = IZERO ROO 1230
I F (KNOWN.LT.IONE) GO TO 30 RO0 1240
DO 10 I=I,KNOWN RO0 1250
II = I RO0 1260
CALL CALCF(RTS(I), F N V ( I ) ) RO0 1270
C NO RECORD ISKEPT OF THE NUMBER OF FUNCTION EVALUATIONS RO0 1280
C USED HERE TO CHECK THE LIST OF KNOWN ROOTS. RO0 1290
I F ( C A B S ( F N V ( I I ) ) . G E . E P 2 ) GO TO '20 RO0 1300
10 CONTINUE RO0 1310
20 I F A I L =IONE RO0 1320
GUESS = GUESS + KNOWN - I I + I O N E RO0 1330
NMORE = NMORE + KNOWN - II +IONE RO0 1340
KNOWN = I I - IONE RO0 1350
30 CONTINUE RO0 1360
LOOP1 = KNOWN + I G N E RO0 1370
LOOP2 = KNOWN + NMORE RO0 1380
I F (LOOP1.GT.LOOP2 .OR. LOOP1.LT.IONE) GO TO 180 RO0 1390
I F (GUESS-NMORE) 40, 70, 60 RO0 1400
40 ILO = GUESS + IONE RO0 1410
DO 50 I=ILO,LOOP2 RO0 1420
RTS(I) = ZERO ROO 1430

J o u r n a l o f C o m p u t a t i o n a l a n d A p p l i e d M a t h e m a t i c s , v o l u m e 4, n o 2, 1 9 7 8 . 164
50 CONTINUE RO0 1440
GO TO 70 RO0 1450
60 CONTINUE RO0 1460
GUESS = NHORE RO0 1470
70 CONTINUE RO0 1480
STEP = HALF RO0 1490
C ROO 1500
C TRY TO FIND NHORE ROOTS IN THIS NAJOR LOOP. RO0 1510
DO 160 NEW=LOOP1,LOOP2 RO0 1520
KOUNT = ITHREE RO0 1530
NEWM1 = NEW - IONE RO0 1540
RT = RTS(NEW) ROO 1550
X1 = RT - STEP RO0 1560
X2 = RT + STEP RO0 1570
X3 = RT RO0 1580
C USE FIRST ESTIHATES° RO0 1590
CALL CALCF(X1, F1) RO0 1600
CALL CALCF(X2, F2) RO0 1610
CALL CALCF(X3, F3) RO0 1620
F S L A S T = F3 RO0 1630
I F (NEW°GT°IONE) CALL TEST(X1, F1, FSAVE, RTS, RO0 1640
NEWN1, E P 2 , KOUNT) RO0 1650
I F (NEWoGT.IONE) CALL TEST(X2~ F2r FSAVE, RTS, RO0 1660
NEWH1, EP2, KOUNT) RO0 1670
I F (NEW°GT°IONE) CALL TEST(X3, F3, FSLAST, RTS, RO0 1680
NEWH1, EP2, KOUNT) RO0 1690
F21 = ( F 2 - F 1 ) / ( X 2 - X 1 ) RO0 1700
C FIND THE ROOTS OF THE QUADRATIC. RO0 1710
80 X32 = X3 - X2 RO0 1720
F32 = ( F 3 - F 2 ) / X 3 2 RO0 1730
F321 = ( F 3 2 - F 2 1 ) / ( X 3 - X 1 ) RO0 1740
B = F32 + X32~F321 RO0 1750
RADICL = B~ITWO - FOUR~F321ZF3 RO0 1760
I F (REALRT °AND° REAL(RADICL).LT°ZERO) RADICL = RO0 1770
ZERO RO0 1780
RADICL = CSQRT(RADICL) RO0 1790
I F (REAL(B)$REAL(RADICL)+AIMAG(B)$AIMAG(RADICL) RO0 1800
• LT.ZERO) RADICL = -RADICL RO0 1810
DENOM = B ÷ RADICL RO0 1820
I F (CABS(DENOH).NE.ZERO) GO TO 100 ROO 1830
I F (CABS(F3).GE.EP2) 8 0 TO 9 0 RO0 1840
XNEW = X3 RO0 1850
GO TO 120 RO0 1860
90 .XNEW = X3 + X32 RO0 1870
GO TO 120 RO0 1880
100 C S T E P = TWO~F3/DENON RO0 1890
I F (.NOT°REALRT °OR° CABS(F3).EO°ZERO .ORo RO0 1900
CABS(F32)°EO°ZERO) GO TO 1 1 0 RO0 1910
CSTEP = F 3 2 / C A B S ( F 3 2 ) ~ F 3 / C A B S ( F 3 ) ~ C A B S ( C S T E P ) RO0 1920
110 XNEW = X3 - CSTEP R O 0 1930
120 CALL CALCF(XNEW, FNEM) RO0 1940
FSAVE = FNEW RO0 1950
I F (NEW°LE°IONE) GO TO 130 RO0 1960
CALL TEST(XNEW, FNEW~ FSAVEp RTS, HEWN1, EP2, RO0 1970
KOUNT) RO0 1980
130 KOUNT = KOUNT + I O N E RO0 1 9 9 0
C TEST ITERATIONS, CONVERGENCE AND DIVERGENCE° RO0 2000
I F (KOUNT°GToHAXITS) GO TO 170 RO0 2010
DIF = XNEW - X3 RO0 2020
I F "(CABS(DIF)°LT°EP11CABS(XNEW)) GO TO 150 ROO 2030
I F (CABS(FSAVE)°LT°EP2) GO TO 150 RO0 2 0 4 0
I F (REALRT °OR° CABS(FSAVE)°LT°HUNDRDZCABS(FSLAST)) RO0 2050
GO TO 1 4 0 ROO 2 0 6 0
C DIVERGENCE " F I X ' , RO0 2 0 7 0
CSTEP = CSTEP~HALF ROO 2080
XNEW = XNEM + CSTEP ROO 2 0 9 0
GO TO 1 2 0 RO0 2 1 0 0
140 X l = X2 RO0 2 1 1 0
X2 = X3 RO0 2 1 2 0
X3 = XNEW RO0 2 1 3 0
F1 = F2 RO0 2 1 4 0
F2 = F3 RO0 2 1 5 0

Journal of Computational and Applied Mathematics, volume 4, no 2, 1978. 165


F3 = FNEW RO0 2160
FSLAST = FSAVE RO0 2170
F21 = F32 RO0 2180
GO TO 80 RO0 2190
150 CONTINUE RO0 2200
C CONVERGENCE TO ONE MORE ROOT. (THE NUMBER OF FUNCTION RO0 2210
C EVALUATIONS USED IN DETERMINING THE CURRENT ROOT IS RO0 2220
C AVAILABLE AT THIS STAGE; OUTPUT THE VARIABLE RO0 2230
C KOUNT I F D E S I R E D , ) RO0 2240
RTS(NEW) = XNEW ROO 2250
FNV(NEW) = FSAVE RO0 2260
NFOUND = NEW RO0 2270
160 CONTINUE RO0 2280
GO TO 190 ROD 2290
170 CONTINUE RO0 2300
C MAXITS REACHED. ROD 2310
RTS(NEW) = XNEW RO0 2320
FNV(NEW) = FSAVE RO0 2330
I F AIL = ITHREE RO0 2340
GO TO 190 RO0 2350
180 CONTINUE RO0 2360
I F A I L = ITWO RO0 2370
190 CONTINUE RO0 2380
RETURN RO0 2390
END RO0 2400

SUBROUTINE TEST(X, F, FSAVE, RTS, K, EPS, KOUNT) TES 10


C TES 20
C THIS SUBROUTINE SERVES TWO PURPOSES: TES 30
C 1 DEFLATION OF THE FUNCTION IS PERFORMED, TES 40
C I . E . IF X IS THE CURRENT APPROXIMATION TO A ROOT TES 50
C A N D RTS IS A VECTOR OF ROOTS ALREADY KNOWN, THE TES 60
C DEFLATED FUNCTION VALUE IS TES 70
C F=(...((F/(X-RTS(1)))/(X-RTS(2)))/...) TES 80
C 2 I F A CURRENT APPROXIMATION TO A ROOT I S "TOO CLOSE" TES 90
C TO A ROOT ALREADY KNOWN, X I S PERTURBED AWAY FROM TES 100
C THE KNOWN ROOT BY 0 . 0 1 . THIS DEVICE AVOIDS DIVISION TES 110
C BY (ESSENTIALLY) ZERO IN THE DEFLATION PROCESS,BUT IT TES 120
C DOES NOT PREVENT CONVERGENCE TO MULTIPLE ZEROS. TES 130
C TES 140
COMPLEX X, F, RTS(K), D, FSAVE TES 150
REAL EPS, CABS TES 160
DATA IONE, PERTB / 1 , 0 . 0 1 E 0 / TES 170
10 CONTINUE TES 180
DO 20 I = I , K TES 190
D = X - RTS(I) TES 200
IF (CABS(D).LEoEPS) GO TO 30 TES 210
F = F/D TES 220
20 CONTINUE TES 230
GO TO 40 TES 240
30 CONTINUE TES 250
X = X + PERTB TES 260
CALL C A L C F ( X , F ) TES 270
FSAVE = F TES 280
KOUNT = KOUNT + I O N E TES 290
GO TO 10 TES 300
40 RETURN TES 310
END TES 320

Journal of Computational and Applied Mathematics, volume 4, no 2, 1978. 166

You might also like