NAG FL Interface
c02agf (poly_​real)

Note: this routine is deprecated. Replaced by c02abf.
Settings help

FL Name Style:


FL Specification Language:


1 Purpose

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

2 Specification

Fortran Interface
Subroutine c02agf ( a, n, scal, z, w, ifail)
Integer, Intent (In) :: n
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: a(n+1)
Real (Kind=nag_wp), Intent (Out) :: z(2,n), w(2*(n+1))
Logical, Intent (In) :: scal
C Header Interface
#include <nag.h>
void  c02agf_ (const double a[], const Integer *n, const logical *scal, double z[], double w[], Integer *ifail)
The routine may be called by the names c02agf or nagf_zeros_poly_real.

3 Description

c02agf attempts to find all the roots of the nth degree real polynomial equation
P(z) = a0 zn + a1 zn-1 + a2 zn-2 + + an-1 z + an = 0 .  
The roots are located using a modified form of Laguerre's method, originally proposed by Smith (1967).
The method of Laguerre (see Wilkinson (1965)) can be described by the iterative scheme
L(zk) = zk+1 - zk = -n P (zk) P (zk) ± H(zk) ,  
where H(zk)=(n-1)[(n-1)(P(zk))2-nP(zk)P(zk)] and z0 is specified.
The sign in the denominator is chosen so that the modulus of the Laguerre step at zk, viz. |L(zk)|, is as small as possible. The 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 z1,z2,z3,, such that |P(zk+1)|<|P(zk)| and ensures that zk+1+L(zk+1) ‘roughly’ lies inside a circular region of radius |F| about zk known to contain a zero of P(z); that is, |L(zk+1)||F|, where F denotes the Fejér bound (see Marden (1966)) at the point zk. Following Smith (1967), F is taken to be min(B,1.445nR) , where B is an upper bound for the magnitude of the smallest zero given by
B = 1.0001 × min( n L (zk) ,|r1|, |an/a0| 1/n ) ,  
r1 is the zero X of smaller magnitude of the quadratic equation
P (zk) 2 n (n-1) X2 + P (zk) n X + 12 P(zk) = 0  
and the Cauchy lower bound R for the smallest zero is computed (using Newton's Method) as the positive root of the polynomial equation
|a0| zn + |a1| zn-1 + |a2| zn-2 ++ |an-1| z - |an| = 0 .  
Starting from the origin, successive iterates are generated according to the rule zk+1 = zk + L (zk) , for k=1 , 2 , 3 ,, and L(zk) is ‘adjusted’ so that |P(zk+1)| < |P(zk)| and |L(zk+1)| |F| . The iterative procedure terminates if P (zk+1) is smaller in absolute value than the bound on the rounding error in P (zk+1) and the current iterate zp = zk+1 is taken to be a zero of P(z) (as is its conjugate z¯p if zp is complex). The deflated polynomial P~ (z) = P (z) / (z-zp) of degree n-1 if zp is real ( P~ (z) = P (z) / ((z-zp)(z-z¯p)) of degree n-2 if zp is complex) is then 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.
Note that c02ajf, c02akf and c02alf can be used to obtain the roots of a quadratic, cubic (n=3) and quartic (n=4) polynomial, respectively.

4 References

Marden M (1966) Geometry of polynomials Mathematical Surveys 3 American Mathematical Society, Providence, RI
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
Thompson K W (1991) Error analysis for polynomial solvers Fortran Journal (Volume 3) 3 10–13
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford

5 Arguments

1: a(n+1) Real (Kind=nag_wp) array Input
On entry: if a is declared with bounds (0:n), a(i) must contain ai (i.e., the coefficient of zn-i ), for i=0,1,,n.
Constraint: a(0) 0.0 .
2: n Integer Input
On entry: n, the degree of the polynomial.
Constraint: n1.
3: scal Logical Input
On entry: indicates whether or not the polynomial is to be scaled. See Section 9 for advice on when it may be preferable to set scal=.FALSE. and for a description of the scaling strategy.
Suggested value: scal=.TRUE..
4: z(2,n) Real (Kind=nag_wp) 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)) Real (Kind=nag_wp) array Workspace
6: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, a(0)=0.0.
Constraint: a(0)0.0.
On entry, n=value.
Constraint: n1.
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.
ifail=3
c02agf cannot evaluate P(z) near some of its zeros without overflow. If this message occurs please contact NAG.
c02agf cannot evaluate P(z) near some of its zeros without underflow. If this message occurs please contact NAG.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

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

8 Parallelism and Performance

c02agf is not threaded in any implementation.

9 Further Comments

If scal=.TRUE., then a scaling factor for the coefficients is chosen as a power of the base b of the machine so that the largest coefficient in magnitude approaches thresh=bemax-p. You should note that no scaling is performed if the largest coefficient in magnitude exceeds thresh, even if scal=.TRUE.. (b, emax and p are defined in Chapter X02.)
However, with scal=.TRUE., overflow may be encountered when the input coefficients a0,a1,a2,,an vary widely in magnitude, particularly on those machines for which b(4p) overflows. In such cases, scal should be set to .FALSE. and the coefficients scaled so that the largest coefficient in magnitude does not exceed b (emax-2p) .
Even so, the scaling strategy used by c02agf is sometimes insufficient to avoid overflow and/or underflow conditions. In such cases, you are 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 dP(cz) for some suitable values of c and d. For example, if the original polynomial was P(z)=2-100+2100z20, then choosing c=2-10 and d=2100, for instance, would yield the scaled polynomial 1+z20, which is well-behaved relative to overflow and underflow and has zeros which are 210 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 nR denote the number of roots found before the failure occurred. Then z(1,n) and z(2,n) contain the real and imaginary parts of the first root found, z(1,n-1) and z(2,n-1) contain the real and imaginary parts of the second root found, , z(1, n- nR+1) and z(2, n- nR+1 ) contain the real and imaginary parts of the nR th root found. After the failure has occurred, the remaining 2× (n-nR) elements of z contain a large negative number (equal to -1 / (x02amf()×2) ).

10 Example

For this routine two examples are presented. There is a single example program for c02agf, with a main program and the code to solve the two example problems given in the subroutines EX1 and EX2.
Example 1 (EX1)
This example finds the roots of the fifth degree polynomial
z5 + 2z4 + 3z3 + 4z2 + 5z + 6=0 .  
Example 2 (EX2)
This example solves the same problem as subroutine EX1, but in addition attempts to estimate the accuracy of the computed roots using a perturbation analysis. Further details can be found in Thompson (1991).

10.1 Program Text

Program Text (c02agfe.f90)

10.2 Program Data

Program Data (c02agfe.d)

10.3 Program Results

Program Results (c02agfe.r)