hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_zeros_poly_real (c02ag)

Purpose

nag_zeros_poly_real (c02ag) finds all the roots of a real polynomial equation, using a variant of Laguerre's method.

Syntax

[z, ifail] = c02ag(a, n, 'scal', scal)
[z, ifail] = nag_zeros_poly_real(a, n, 'scal', scal)

Description

nag_zeros_poly_real (c02ag) attempts to find all the roots of the nnth degree real polynomial equation
P(z) = a0 zn + a1 zn1 + a2 zn2 + + an1 z + an = 0 .
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) ± sqrt(H(zk)) ) ,
L(zk) = zk+1 - zk = -n P (zk) P (zk) ± H(zk) ,
where H(zk) = (n1)[(n1)(P(zk))2nP(zk)P(zk)]H(zk)=(n-1)[(n-1)(P(zk))2-nP(zk)P(zk)] and z0z0 is specified.
The sign in the denominator is chosen so that the modulus of the Laguerre step at zkzk, viz. |L(zk)||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 function generates a sequence of iterates z1,z2,z3,z1,z2,z3,, such that |P(zk + 1)| < |P(zk)||P(zk+1)|<|P(zk)| and ensures that zk + 1 + L(zk + 1)zk+1+L(zk+1) ‘roughly’ lies inside a circular region of radius |F||F| about zkzk known to contain a zero of P(z)P(z); that is, |L(zk + 1)||F||L(zk+1)||F|, where FF denotes the Fejér bound (see Marden (1966)) at the point zkzk. Following Smith (1967), FF is taken to be min (B,1.445nR) min(B,1.445nR) , where BB is an upper bound for the magnitude of the smallest zero given by
B = 1.0001 × min ( sqrt(n) L (zk) ,|r1|,|an / a0|1 / n) ,
B = 1.0001 × min( n L (zk) ,|r1|, | an / a0| 1/n ) ,
r1r1 is the zero XX of smaller magnitude of the quadratic equation
( P (zk) )/( 2 n (n1) ) X2 + ( P (zk) )/n X + (1/2) P(zk) = 0
P (zk) 2 n (n-1) X2 + P (zk) n X + 12 P(zk) = 0
and the Cauchy lower bound RR for the smallest zero is computed (using Newton's Method) as the positive root of the polynomial equation
|a0| zn + |a1| zn1 + |a2| zn2 + + |an1| z |an| = 0 .
|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) zk+1 = zk + L (zk) , for k = 1 , 2 , 3 , k=1 , 2 , 3 ,, and L(zk)L(zk) is ‘adjusted’ so that |P(zk + 1)| < |P(zk)| | P ( zk+1 ) | < | P ( zk ) |  and |L(zk + 1)| |F| | L ( zk+1 ) | |F| . The iterative procedure terminates if P (zk + 1) P (zk+1)  is smaller in absolute value than the bound on the rounding error in P (zk + 1) P (zk+1)  and the current iterate zp = zk + 1 zp = zk+1  is taken to be a zero of P(z)P(z) (as is its conjugate zp z-p  if zpzp is complex). The deflated polynomial (z) = P (z) / (zzp) P~ (z) = P (z) / (z-zp)  of degree n1n-1 if zpzp is real ( (z) = P (z) / ((zzp)(zzp)) P~ (z) = P (z) / ( (z-zp) (z-z-p) )  of degree n2n-2 if zpzp is complex) is then formed, and the above procedure is repeated on the deflated polynomial until n < 3n<3, whereupon the remaining roots are obtained via the ‘standard’ closed formulae for a linear (n = 1n=1) or quadratic (n = 2n=2) equation.
Note that nag_zeros_quadratic_real (c02aj), nag_zeros_cubic_real (c02ak) and nag_zeros_quartic_real (c02al) can be used to obtain the roots of a quadratic, cubic (n = 3n=3) and quartic (n = 4n=4) polynomial, respectively.

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

Parameters

Compulsory Input Parameters

1:     a(n + 1n+1) – double array
if a is declared with bounds (0 : n)(0:n), then a(i) ai  must contain ai ai  (i.e., the coefficient of zni zn-i ) , for i = 0,1,,ni=0,1,,n.
Constraint: a(1) 0.0 a1 0.0 .
2:     n – int64int32nag_int scalar
nn, the degree of the polynomial.
Constraint: n1n1.

Optional Input Parameters

1:     scal – logical scalar
Indicates whether or not the polynomial is to be scaled. See Section [Further Comments] for advice on when it may be preferable to set scal = falsescal=false and for a description of the scaling strategy.
Default: truetrue

Input Parameters Omitted from the MATLAB Interface

w

Output Parameters

1:     z(22,n) – double array
The real and imaginary parts of the roots are stored in z(1,i) z1i and z(2,i) z2i respectively, for i = 1,2,,ni=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) z1i+1 = z1i and z(2,i + 1) = z(2,i) z2i+1 = -z2i .
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,a(0) = 0.0a0=0.0,
orn < 1n<1.
  ifail = 2ifail=2
The iterative procedure has failed to converge. This error is very unlikely to occur. If it does, please contact NAG, as some basic assumption for the arithmetic has been violated. See also Section [Further Comments].
  ifail = 3ifail=3
Either overflow or underflow prevents the evaluation of P(z)P(z) near some of its zeros. This error is very unlikely to occur. If it does, please contact NAG. See also Section [Further Comments].

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 [Example].

Further Comments

If scal = truescal=true, then a scaling factor for the coefficients is chosen as a power of the base bb of the machine so that the largest coefficient in magnitude approaches thresh = bemaxpthresh=bemax-p. You should note that no scaling is performed if the largest coefficient in magnitude exceeds threshthresh, even if scal = truescal=true. (bb, emaxemax and pp are defined in Chapter X02.)
However, with scal = truescal=true, overflow may be encountered when the input coefficients a0,a1,a2,,ana0,a1,a2,,an vary widely in magnitude, particularly on those machines for which b(4p) 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(emax2p) b (emax-2p) .
Even so, the scaling strategy used by nag_zeros_poly_real (c02ag) is sometimes insufficient to avoid overflow and/or underflow conditions. In such cases, you are recommended to scale the independent variable (z)(z) so that the disparity between the largest and smallest coefficient in magnitude is reduced. That is, use the function to locate the zeros of the polynomial dP(cz)dP(cz) for some suitable values of cc and dd. For example, if the original polynomial was P(z) = 2100 + 2100z20P(z)=2-100+2100z20, then choosing c = 210c=2-10 and d = 2100d=2100, for instance, would yield the scaled polynomial 1 + z201+z20, which is well-behaved relative to overflow and underflow and has zeros which are 210210 times those of P(z)P(z).
If the function fails with ifail = 2ifail=2 or 33, 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 nR  denote the number of roots found before the failure occurred. Then z(1,n) z1n  and z(2,n) z2n  contain the real and imaginary parts of the first root found, z(1,n1) z1n-1  and z(2,n1) z2n-1  contain the real and imaginary parts of the second root found, , z(1, n nR + 1) , z1 n- nR+1  and z(2, n nR + 1 ) z2 n- nR+1  contain the real and imaginary parts of the nR nR th root found. After the failure has occurred, the remaining 2 × (nnR) 2× (n-nR)  elements of z contain a large negative number (equal to 1 / (x02am() × sqrt(2)) -1 / (x02am()×2) ).

Example

function nag_zeros_poly_real_example
a = [1;
     2;
     3;
     4;
     5;
     6];
n = 5;
[z, ifail] = nag_zeros_poly_real(a, int64(n));

% Estimate the accuracy of the computed roots using a perturbation analysis

% Form the coefficients of the perturbed polynomial
abar = a;
epsbar = 3*x02aj;
for i=1:2:n+1
  abar(i) = (1+epsbar)*abar(i);
end
for i=2:2:n+1
  abar(i) = (1-epsbar)*abar(i);
end

% Compute the roots of the perturbed polynomial
[zbar, ifail] = nag_zeros_poly_real(abar, int64(n));


% Perform error analysis

% Initialise markers to 0 (unmarked)
m =zeros(n, 1);
r =zeros(n, 1);
rmax = x02al;

for i=1:n
  deltai = rmax;
  r1 = abs(complex(z(1,i), z(2,i)));

  % Loop over all perturbed roots (stored in zbar)
  for j=1:n
    % Compare the current unperturbed root to all unmarked perturbed roots.
    if m(j) == 0
      r2 = abs(complex(zbar(1,j), zbar(2,j)));
      deltac = abs(r1-r2);

      if deltac < deltai
        deltai = deltac;
        jmin = j;
      end
    end
  end

  % Mark the selected perturbed root
  m(jmin) = 1;

  % Compute the relative error
  if r1 ~= 0
    r3 = abs(complex(zbar(1,jmin),zbar(2,jmin)));
    di = min(r1,r3);
    r(i) = max(deltai/max(di,deltai/rmax),x02aj);
  end

end

fprintf('\n   Computed Roots of Polynomial       Error Estimate\n');
fprintf('                                    (machine dependent)\n');
for i=1:n
  fprintf(' z = %12.4e%+12.4ei       %9.1e\n', z(1,i), z(2,i), r(i));
end
 

   Computed Roots of Polynomial       Error Estimate
                                    (machine dependent)
 z =  -1.4918e+00 +0.0000e+00i         1.2e-15
 z =   5.5169e-01 +1.2533e+00i         1.1e-16
 z =   5.5169e-01 -1.2533e+00i         1.1e-16
 z =  -8.0579e-01 +1.2229e+00i         1.1e-16
 z =  -8.0579e-01 -1.2229e+00i         1.1e-16

function c02ag_example
a = [1;
     2;
     3;
     4;
     5;
     6];
n = 5;
[z, ifail] = c02ag(a, int64(n));

% Estimate the accuracy of the computed roots using a perturbation analysis

% Form the coefficients of the perturbed polynomial
abar = a;
epsbar = 3*x02aj;
for i=1:2:n+1
  abar(i) = (1+epsbar)*abar(i);
end
for i=2:2:n+1
  abar(i) = (1-epsbar)*abar(i);
end

% Compute the roots of the perturbed polynomial
[zbar, ifail] = c02ag(abar, int64(n));


% Perform error analysis

% Initialise markers to 0 (unmarked)
m =zeros(n, 1);
r =zeros(n, 1);
rmax = x02al;

for i=1:n
  deltai = rmax;
  r1 = abs(complex(z(1,i), z(2,i)));

  % Loop over all perturbed roots (stored in zbar)
  for j=1:n
    % Compare the current unperturbed root to all unmarked perturbed roots.
    if m(j) == 0
      r2 = abs(complex(zbar(1,j), zbar(2,j)));
      deltac = abs(r1-r2);

      if deltac < deltai
        deltai = deltac;
        jmin = j;
      end
    end
  end

  % Mark the selected perturbed root
  m(jmin) = 1;

  % Compute the relative error
  if r1 ~= 0
    r3 = abs(complex(zbar(1,jmin),zbar(2,jmin)));
    di = min(r1,r3);
    r(i) = max(deltai/max(di,deltai/rmax),x02aj);
  end

end

fprintf('\n   Computed Roots of Polynomial       Error Estimate\n');
fprintf('                                    (machine dependent)\n');
for i=1:n
  fprintf(' z = %12.4e%+12.4ei       %9.1e\n', z(1,i), z(2,i), r(i));
end
 

   Computed Roots of Polynomial       Error Estimate
                                    (machine dependent)
 z =  -1.4918e+00 +0.0000e+00i         1.2e-15
 z =   5.5169e-01 +1.2533e+00i         1.1e-16
 z =   5.5169e-01 -1.2533e+00i         1.1e-16
 z =  -8.0579e-01 +1.2229e+00i         1.1e-16
 z =  -8.0579e-01 -1.2229e+00i         1.1e-16


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013