
     C02(3NAG)         Foundation Library (12/10/92)         C02(3NAG)

          C02 -- Zeros of Polynomials                   Introduction -- C02
                                    Chapter C02
                               Zeros of Polynomials

          1. Scope of the Chapter

          This chapter is concerned with computing the zeros of a
          polynomial with real or complex coefficients.

          2. Background to the Problems

          Let f(z) be a polynomial of degree n with complex coefficients
          a :
           i

                            n    n-1    n-2
                   f(z)==a z +a z   +a z   +...+a   z+a ,  a /=0.
                          0    1      2          n-1   n    0

          A complex number z  is called a zero of f(z) (or equivalently a
                            1
          root of the equation f(z)=0), if:

                                      f(z )=0.
                                         1

          If z  is a zero, then f(z) can be divided by a factor (z-z ):
              1                                                     1

                                f(z)=(z-z )f (z)                        (1)
                                         1  1

          where f (z) is a polynomial of degree n-1. By the Fundamental
                 1
          Theorem of Algebra, a polynomial f(z) always has a zero, and so
          the process of dividing out factors (z-z ) can be continued until
                                                  i
          we have a complete factorization of f(z)

                           f(z)==a (z-z )(z-z )...(z-z ).
                                  0    1     2        n

          Here the complex numbers z ,z ,...,z  are the zeros of f(z); they
                                    1  2      n
          may not all be distinct, so it is sometimes more convenient to
          write:

                                   m       m          m
                                    1       2          k
                     f(z)==a (z-z )  (z-z )  ...(z-z )  ,  k<=n,
                            0    1       2          k

          with distinct zeros z ,z ,...,z  and multiplicities m >=1. If
                               1  2      k                     i
          m =1, z  is called a single zero, if m >1, z  is called a
           i     i                              i     i
          multiple or repeated zero; a multiple zero is also a zero of the
          derivative of f(z).

          If the coefficients of f(z) are all real, then the zeros of f(z)
          are either real or else occur as pairs of conjugate complex
          numbers x+iy and x-iy. A pair of complex conjugate zeros are the
                                                 2
          zeros of a quadratic factor of f(z), (z +rz+s), with real
          coefficients r and s.

          Mathematicians are accustomed to thinking of polynomials as
          pleasantly simple functions to work with. However the problem of
          numerically computing the zeros of an arbitrary polynomial is far
          from simple. A great variety of algorithms have been proposed, of
          which a number have been widely used in practice; for a fairly
          comprehensive survey, see Householder [1]. All general algorithms
          are iterative. Most converge to one zero at a time; the
          corresponding factor can then be divided out as in equation (1)
          above - this process is called deflation or, loosely, dividing
          out the zero - and the algorithm can be applied again to the
          polynomial f (z). A pair of complex conjugate zeros can be
                      1
          divided out together - this corresponds to dividing f(z) by a
          quadratic factor.

          Whatever the theoretical basis of the algorithm, a number of
          practical problems arise: for a thorough discussion of some of
          them see Peters and Wilkinson [2] and Wilkinson [3]. The most
          elementary point is that, even if z  is mathematically an exact
                                             1
          zero of f(z), because of the fundamental limitations of computer
          arithmetic the computed value of f(z ) will not necessarily be
                                              1
          exactly 0.0. In practice there is usually a small region of
          values of z about the exact zero at which the computed value of
          f(z) becomes swamped by rounding errors. Moreover in many
          algorithms this inaccuracy in the computed value of f(z) results
          in a similar inaccuracy in the computed step from one iterate to
          the next. This limits the precision with which any zero can be
          computed. Deflation is another potential cause of trouble, since,
          in the notation of equation (1), the computed coefficients of
          f (z) will not be completely accurate, especially if z  is not an
           1                                                    1
          exact zero of f(z); so the zeros of the computed f (z) will
                                                            1
          deviate from the zeros of f(z).

          A zero is called ill-conditioned if it is sensitive to small
          changes in the coefficients of the polynomial. An ill-conditioned
          zero is likewise sensitive to the computational inaccuracies just
          mentioned. Conversely a zero is called well-conditioned if it is
          comparatively insensitive to such perturbations. Roughly speaking
          a zero which is well separated from other zeros is well-
          conditioned, while zeros which are close together are ill-
          conditioned, but in talking about 'closeness' the decisive factor
          is not the absolute distance between neighbouring zeros but their
          ratio: if the ratio is close to 1 the zeros are ill-conditioned.
          In particular, multiple zeros are ill-conditioned. A multiple
          zero is usually split into a cluster of zeros by perturbations in
          the polynomial or computational inaccuracies.

          2.1. References

          [1]   Householder A S (1970) The Numerical Treatment of a Single
                Nonlinear Equation. McGraw-Hill.

          [2]   Peters G and Wilkinson J H (1971) Practical Problems Arising
                in the Solution of Polynomial Equations. J. Inst. Maths
                Applics. 8 16--35.

          [3]   Wilkinson J H (1963) Rounding Errors in Algebraic Processes,
                Chapter 2. HMSO.

          3. Recommendations on Choice and Use of Routines

          3.1. Discussion

          Two routines are available: C02AFF for polynomials with complex
          coefficients and C02AGF for polynomials with real coefficients.

          C02AFF and C02AGF both use a variant of Laguerre's Method due to
          BT Smith to calculate each zero until the degree of the deflated
          polynomial is less than 3, whereupon the remaining zeros are
          obtained using the 'standard' closed formulae for a quadratic or
          linear equation.

          The accuracy of the roots will depend on how ill-conditioned they
          are. Peters and Wilkinson [2] describe techniques for estimating
          the errors in the zeros after they have been computed.

          3.2. Index

           Zeros of a complex polynomial                             C02AFF
           Zeros of a real polynomial                                C02AGF


          C02 -- Zeros of Polynomials                       Contents -- C02
          Chapter C02

          Zeros of Polynomials

          C02AFF  All zeros of complex polynomial, modified Laguerre method

          C02AGF  All zeros of real polynomial, modified Laguerre method

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

     C02AFF(3NAG)      Foundation Library (12/10/92)      C02AFF(3NAG)

          C02 -- Zeros of Polynomials                                C02AFF
                  C02AFF -- NAG Foundation Library Routine Document

          Note: Before using this routine, please read the Users' Note for
          your implementation to check implementation-dependent details.
          The symbol (*) after a NAG routine name denotes a routine that is
          not included in the Foundation Library.

          1. Purpose

          C02AFF finds all the roots of a complex polynomial equation,
          using a variant of Laguerre's Method.

          2. Specification

                 SUBROUTINE C02AFF (A, N, SCALE, Z, W, IFAIL)
                 INTEGER          N, IFAIL
                 DOUBLE PRECISION A(2,N+1), Z(2,N), W(4*(N+1))
                 LOGICAL          SCALE

          3. Description

          The routine attempts to find all the roots of the nth degree
          complex polynomial equation

                               n    n-1    n-2
                       P(z)=a z +a z   +a z   +...+a   z+a =0.
                             0    1      2          n-1   n

          The roots are located using a modified form of Laguerre's Method,
          originally proposed by Smith [2].

          The method of Laguerre [3] can be described by the iterative
          scheme

                                             -n*P(z )
                                                   k
                          L(z )=z   -z = ----------------,
                             k   k+1  k             
                                         P'(z )+-  /H(z )
                                             k   \/    k

                                           2
          where H(z )=(n-1)*[(n-1)*(P'(z )) -n*P(z )P''(z )], and z  is
                   k                    k         k      k         0
          specified.

          The sign in the denominator is chosen so that the modulus of the
          Laguerre step at z , viz. |L(z )|, is as small as possible. The
                            k           k
          method can be shown to be cubically convergent for isolated roots
          (real or complex) and linearly convergent for multiple roots.
          The routine generates a sequence of iterates z , z , z ,..., such
                                                        1   2   3
          that |P(z   )|<|P(z )| and ensures that z   +L(z   ) 'roughly'
                   k+1       k                     k+1    k+1
          lies inside a circular region of radius |F| about z  known to
                                                             k
          contain a zero of P(z); that is, |L(z   )|<=|F|, where F denotes
                                               k+1
          the Fejer bound (see Marden [1]) at the point z . Following Smith
                                                         k
          [2], F is taken to be min(B,1.445*n*R), where B is an upper bound
          for the magnitude of the smallest zero given by

                                                         1/n
                      B=1.0001*min(\/n*L(z ),|r |,|a /a |   ),
                                          k    1    n  0

          r  is the zero X of smaller magnitude of the quadratic equation
           1

                                           2
                    2(P''(z )/(2*n*(n-1)))X +2(P'(z )/n)X+P(z )=0
                           k                       k         k

          and the Cauchy lower bound R for the smallest zero is computed
          (using Newton's Method) as the positive root of the polynomial
          equation

                         n      n-1      n-2
                    |a |z +|a |z   +|a |z   +...+|a   |z-|a |=0.
                      0      1        2            n-1     n

          Starting from the origin, successive iterates are generated
          according to the rule z   =z +L(z ) for k = 1,2,3,... and L(z )
                                 k+1  k    k                           k
          is 'adjusted' so that |P(z   )|<|P(z )| and |L(z   )|<=|F|. The
                                    k+1       k           k+1
          iterative procedure terminates if P(z   ) is smaller in absolute
                                               k+1
          value than the bound on the rounding error in P(z   ) and the
                                                           k+1
          current iterate z =z    is taken to be a zero of P(z). The
                           p  k+1
                              ~
          deflated polynomial P(z)=P(z)/(z-z ) of degree n-1 is then
                                            p
          formed, and the above procedure is repeated on the deflated
          polynomial until n<3, whereupon the remaining roots are obtained
          via the 'standard' closed formulae for a linear (n = 1) or
          quadratic (n = 2) equation.

          To obtain the roots of a quadratic polynomial, C02AHF(*) can be
          used.

          4. References

          [1]   Marden M (1966) Geometry of Polynomials. Mathematical
                Surveys. 3 Am. Math. Soc., Providence, RI.

          [2]   Smith B T (1967) ZERPOL: A Zero Finding Algorithm for
                Polynomials Using Laguerre's Method. Technical Report.
                Department of Computer Science, University of Toronto,
                Canada.

          [3]   Wilkinson J H (1965) The Algebraic Eigenvalue Problem.
                Clarendon Press.

          5. Parameters

           1:  A(2,N+1) -- DOUBLE PRECISION array                     Input
               On entry: if A is declared with bounds (2,0:N), then A(1,i)
               and A(2,i) must contain the real and imaginary parts of a
                                                                        i
                                          n-i
               (i.e., the coefficient of z   ), for i=0,1,...,n.
               Constraint: A(1,0) /= 0.0 or A(2,0) /= 0.0.

           2:  N -- INTEGER                                           Input
               On entry: the degree of the polynomial, n. Constraint: N >=
               1.

           3:  SCALE -- LOGICAL                                       Input
               On entry: indicates whether or not the polynomial is to be
               scaled. See Section 8 for advice on when it may be
               preferable to set SCALE = .FALSE. and for a description of
               the scaling strategy. Suggested value: SCALE = .TRUE..

           4:  Z(2,N) -- DOUBLE PRECISION array                      Output
               On exit: the real and imaginary parts of the roots are
               stored in Z(1,i) and Z(2,i) respectively, for i=1,2,...,n.

           5:  W(4*(N+1)) -- DOUBLE PRECISION array               Workspace

           6:  IFAIL -- INTEGER                                Input/Output
               On entry: IFAIL must be set to 0, -1 or 1. For users not
               familiar with this parameter (described in the Essential
               Introduction) the recommended value is 0.

               On exit: IFAIL = 0 unless the routine detects an error (see
               Section 6).

          6. Error Indicators and Warnings

          Errors detected by the routine:

          If on entry IFAIL = 0 or -1, explanatory error messages are
          output on the current error message unit (as defined by X04AAF).

          IFAIL= 1
               On entry A(1,0) = 0.0 and A(2,0) = 0.0,

               or       N < 1.

          IFAIL= 2
               The iterative procedure has failed to converge. This error
               is very unlikely to occur. If it does, please contact NAG
               immediately, as some basic assumption for the arithmetic has
               been violated. See also Section 8.

          IFAIL= 3
               Either overflow or underflow prevents the evaluation of P(z)
               near some of its zeros. This error is very unlikely to
               occur. If it does, please contact NAG immediately. See also
               Section 8.

          7. Accuracy

          All roots are evaluated as accurately as possible, but because of
          the inherent nature of the problem complete accuracy cannot be
          guaranteed.

          8. Further Comments

          If SCALE = .TRUE., then a scaling factor for the coefficients is
          chosen as a power of the base B of the machine so that the
                                                                EMAX-P
          largest coefficient in magnitude approaches THRESH = B      .
          Users should note that no scaling is performed if the largest
          coefficient in magnitude exceeds THRESH, even if SCALE = .TRUE..
          (For definition of B, EMAX and P see the Chapter Introduction
          X02.)

          However, with SCALE = .TRUE., overflow may be encountered when
          the input coefficients a ,a ,a ,...,a  vary widely in magnitude,
                                  0  1  2      n
                                                    (4*P)
          particularly on those machines for which B      overflows. In
          such cases, SCALE should be set to .FALSE. and the coefficients
          scaled so that the largest coefficient in magnitude does not
                  (EMAX-2*P)
          exceed B          .

          Even so, the scaling strategy used in C02AFF is sometimes
          insufficient to avoid overflow and/or underflow conditions. In
          such cases, the user is recommended to scale the independent
          variable (z) so that the disparity between the largest and
          smallest coefficient in magnitude is reduced. That is, use the
          routine to locate the zeros of the polynomial d*P(cz) for some
          suitable values of c and d. For example, if the original
                               -100   100 20                   -10
          polynomial was P(z)=2    i+2   z  , then choosing c=2    and
             100                                                     20
          d=2   , for instance, would yield the scaled polynomial i+z  ,
          which is well-behaved relative to overflow and underflow and has
                           10
          zeros which are 2   times those of P(z).

          If the routine fails with IFAIL = 2 or 3, then the real and
          imaginary parts of any roots obtained before the failure occurred
          are stored in Z in the reverse order in which they were found.
          Let n  denote the number of roots found before the failure
               R
          occurred. Then Z(1,n) and Z(2,n) contain the real and imaginary
          parts of the 1st root found, Z(1,n-1) and Z(2,n-1) contain the
          real and imaginary parts of the 2nd root found, ..., Z(1,n ) and
                                                                    R
          Z(2,n ) contain the real and imaginary parts of the n th root
               R                                               R
          found. After the failure has occurred, the remaining 2*(n-n )
                                                                     R
          elements of Z contain a large negative number (equal to
                         

          -1/(X02AMF().\/2)).

          9. Example

                                                 5    4    3    2
          To find the roots of the polynomial a z +a z +a z +a z +a z+a =0,
                                               0    1    2    3    4   5
          where a =(5.0+6.0i), a =(30.0+20.0i), a =-(0.2+6.0i),
                 0              1                2
          a =(50.0+100000.0i), a =-(2.0-40.0i) and a =(10.0+1.0i).
           3                    4                   5

          The example program is not reproduced here. The source code for
          all example programs is distributed with the NAG Foundation
          Library software and should be available on-line.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

     C02AGF(3NAG)      Foundation Library (12/10/92)      C02AGF(3NAG)

          C02 -- Zeros of Polynomials                                C02AGF
                  C02AGF -- NAG Foundation Library Routine Document

          Note: Before using this routine, please read the Users' Note for
          your implementation to check implementation-dependent details.
          The symbol (*) after a NAG routine name denotes a routine that is
          not included in the Foundation Library.

          1. Purpose

          C02AGF finds all the roots of a real polynomial equation, using a
          variant of Laguerre's Method.

          2. Specification

                 SUBROUTINE C02AGF (A, N, SCALE, Z, W, IFAIL)
                 INTEGER          N, IFAIL
                 DOUBLE PRECISION A(N+1), Z(2,N), W(2*(N+1))
                 LOGICAL          SCALE

          3. Description

          The routine attempts to find all the roots of the nth degree real
          polynomial equation

                               n    n-1    n-2
                       P(z)=a z +a z   +a z   +...+a   z+a =0.
                             0    1      2          n-1   n

          The roots are located using a modified form of Laguerre's Method,
          originally proposed by Smith [2].

          The method of Laguerre [3] can be described by the iterative
          scheme

                                             -n*P(z )
                                                   k
                          L(z )=z   -z = ----------------,
                             k   k+1  k             
                                         P'(z )+-  /H(z )
                                             k   \/    k

                                           2
          where H(z )=(n-1)*[(n-1)*(P'(z )) -n*P(z )P''(z )], and z  is
                   k                    k         k      k         0
          specified.

          The sign in the denominator is chosen so that the modulus of the
          Laguerre step at z , viz. |L(z )|, is as small as possible. The
                            k           k
          method can be shown to be cubically convergent for isolated roots
          (real or complex) and linearly convergent for multiple roots.
          The routine generates a sequence of iterates z , z , z ,..., such
                                                        1   2   3
          that |P(z +1)|<|P(z )| and ensures that z   +L(z   ) 'roughly'
                   k         k                     k+1    k+1
          lies inside a circular region of radius |F| about z  known to
                                                             k
          contain a zero of P(z); that is, |L(z   )|<=|F|, where F denotes
                                               k+1
          the Fejer bound (see Marden [1]) at the point z . Following Smith
                                                         k
          [2], F is taken to be min(B,1.445*n*R), where B is an upper bound
          for the magnitude of the smallest zero given by

                                                         1/n
                      B=1.0001*min(\/n*L(z ),|r |,|a /a |   ),
                                          k    1    n  0

          r  is the zero X of smaller magnitude of the quadratic equation
           1

                                           2
                    2(P''(z )/(2*n*(n-1)))X +2(P'(z )/n)X+P(z )=0
                           k                       k         k

          and the Cauchy lower bound R for the smallest zero is computed
          (using Newton's Method) as the positive root of the polynomial
          equation

                         n      n-1      n-2
                    |a |z +|a |z   +|a |z   +...+|a   |z-|a |=0.
                      0      1        2            n-1     n

          Starting from the origin, successive iterates are generated
          according to the rule z   =z +L(z ) for k=1,2,3,... and L(z ) is
                                 k+1  k    k                         k
                                 k+1       k           k+1
          iterative procedure terminates if P(z   ) is smaller in absolute
                                               k+1
          value than the bound on the rounding error in P(z   ) and the
                                                           k+1
          current iterate z =z    is taken to be a zero of P(z) (as is its
                           p  k-1
                    

          conjugate z  if z  is complex). The deflated polynomial
                     p     p
          ~
          P(z)=P(z)/(z-z ) of degree n-1 if z  is real
                        p                    p
           ~                   
          (P(z)=P(z)/((z-z )(z-z )) of degree n-2 if z  is complex) is then
                          p     p                     p
          formed, and the above procedure is repeated on the deflated
          polynomial until n<3, whereupon the remaining roots are obtained
          via the 'standard' closed formulae for a linear (n = 1) or
          quadratic (n = 2) equation.

          To obtain the roots of a quadratic polynomial, C02AJF(*) can be
          used.

          4. References

          [1]   Marden M (1966) Geometry of Polynomials. Mathematical
                Surveys. 3 Am. Math. Soc., Providence, RI.

          [2]   Smith B T (1967) ZERPOL: A Zero Finding Algorithm for
                Polynomials Using Laguerre's Method. Technical Report.
                Department of Computer Science, University of Toronto,
                Canada.

          [3]   Wilkinson J H (1965) The Algebraic Eigenvalue Problem.
                Clarendon Press.

          5. Parameters

           1:  A(N+1) -- DOUBLE PRECISION array                       Input
               On entry: if A is declared with bounds (0:N), then A(i)
                                                          n-i
               must contain a  (i.e., the coefficient of z   ), for
                             i
               i=0,1,...,n. Constraint: A(0) /= 0.0.

           2:  N -- INTEGER                                           Input
               On entry: the degree of the polynomial, n. Constraint: N >=
               1.

           3:  SCALE -- LOGICAL                                       Input
               On entry: indicates whether or not the polynomial is to be
               scaled. See Section 8 for advice on when it may be
               preferable to set SCALE = .FALSE. and for a description of
               the scaling strategy. Suggested value: SCALE = .TRUE..

           4:  Z(2,N) -- DOUBLE PRECISION array                      Output
               On exit: the real and imaginary parts of the roots are
               stored in Z(1,i) and Z(2,i) respectively, for i=1,2,...,n.
               Complex conjugate pairs of roots are stored in consecutive
               pairs of elements of Z; that is, Z(1,i+1) = Z(1,i) and
               Z(2,i+1)=-Z(2,i).

           5:  W(2*(N+1)) -- DOUBLE PRECISION array               Workspace

           6:  IFAIL -- INTEGER                                Input/Output
               On entry: IFAIL must be set to 0, -1 or 1. For users not
               familiar with this parameter (described in the Essential
               Introduction) the recommended value is 0.
               On exit: IFAIL = 0 unless the routine detects an error (see
               Section 6).

          6. Error Indicators and Warnings

          Errors detected by the routine:

          If on entry IFAIL = 0 or -1, explanatory error messages are
          output on the current error message unit (as defined by X04AAF).

          IFAIL= 1
               On entry A(0) = 0.0,

               or       N < 1.

          IFAIL= 2
               The iterative procedure has failed to converge. This error
               is very unlikely to occur. If it does, please contact NAG
               immediately, as some basic assumption for the arithmetic has
               been violated. See also Section 8.

          IFAIL= 3
               Either overflow or underflow prevents the evaluation of P(z)
               near some of its zeros. This error is very unlikely to
               occur. If it does, please contact NAG immediately. See also
               Section 8.

          7. Accuracy

          All roots are evaluated as accurately as possible, but because of
          the inherent nature of the problem complete accuracy cannot be
          guaranteed.

          8. Further Comments

          If SCALE = .TRUE., then a scaling factor for the coefficients is
          chosen as a power of the base B of the machine so that the
                                                                EMAX-P
          largest coefficient in magnitude approaches THRESH = B      .
          Users should note that no scaling is performed if the largest
          coefficient in magnitude exceeds THRESH, even if SCALE = .TRUE..
          (For definition of B, EMAX and P see the Chapter Introduction
          X02.)

          However, with SCALE = .TRUE., overflow may be encountered when
          the input coefficients a ,a ,a ,...,a  vary widely in magnitude,
                                  0  1  2      n
                                                    (4*P)
          particularly on those machines for which B      overflows. In
          such cases, SCALE should be set to .FALSE. and the coefficients
          scaled so that the largest coefficient in magnitude does not
                  (EMAX-2*P)
          exceed B          .

          Even so, the scaling strategy used in C02AGF is sometimes
          insufficient to avoid overflow and/or underflow conditions. In
          such cases, the user is recommended to scale the independent
          variable (z) so that the disparity between the largest and
          smallest coefficient in magnitude is reduced. That is, use the
          routine to locate the zeros of the polynomial d*P(cz) for some
          suitable values of c and d. For example, if the original
                               -100  100 20                   -10
          polynomial was P(z)=2    +2   z  , then choosing c=2    and
             100                                                     20
          d=2   , for instance, would yield the scaled polynomial 1+z  ,
          which is well-behaved relative to overflow and underflow and has
                           10
          zeros which are 2   times those of P(z).

          If the routine fails with IFAIL = 2 or 3, then the real and
          imaginary parts of any roots obtained before the failure occurred
          are stored in Z in the reverse order in which they were found.
          Let n  denote the number of roots found before the failure
               R
          occurred. Then Z(1,n) and Z(2,n) contain the real and imaginary
          parts of the 1st root found, Z(1,n-1) and Z(2,n-1) contain the
          real and imaginary parts of the 2nd root found, ..., Z(1,n ) and
                                                                    R
          Z(2,n ) contain the real and imaginary parts of the n th root
               R                                               R
          found. After the failure has occurred, the remaining 2*(n-n )
                                                                     R
          elements of Z contain a large negative number (equal to
                         

          -1/(X02AMF().\/2)).

          9. Example

          To find the roots of the 5th degree polynomial
           5   4   3   2
          z +2z +3z +4z +5z+6=0.

          The example program is not reproduced here. The source code for
          all example programs is distributed with the NAG Foundation
          Library software and should be available on-line.

