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_complex (c02af)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_zeros_poly_complex (c02af) finds all the roots of a complex polynomial equation, using a variant of Laguerre's method.

Syntax

[z, ifail] = c02af(a, n, 'scal', scal)
[z, ifail] = nag_zeros_poly_complex(a, n, 'scal', scal)

Description

nag_zeros_poly_complex (c02af) attempts to find all the roots of the nth degree complex polynomial equation
Pz = 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
Lzk = zk+1 - zk = -n P zk P zk ± Hzk ,  
where Hzk=n-1n-1Pzk2-nPzkPzk and z0 is specified.
The sign in the denominator is chosen so that the modulus of the Laguerre step at zk, viz. Lzk, 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,, such that Pzk+1<Pzk and ensures that zk+1+Lzk+1 ‘roughly’ lies inside a circular region of radius F about zk known to contain a zero of Pz; that is, Lzk+1F, where F denotes the Fejér bound (see Marden (1966)) at the point zk. Following Smith (1967), F is taken to be minB,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 Pzk = 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 Lzk 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 Pz. The deflated polynomial P~ z = P z / z-zp  of degree n-1 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 nag_zeros_quadratic_complex (c02ah), nag_zeros_cubic_complex (c02am) and nag_zeros_quartic_complex (c02an) can be used to obtain the roots of a quadratic, cubic (n=3) and quartic (n=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:     a2n+1 – double array
a1i+1 and a2i+1 must contain the real and imaginary parts of ai (i.e., the coefficient of zn-i), for i=0,1,,n.
Constraint: a11 0.0  or a21 0.0 .
2:     n int64int32nag_int scalar
n, the degree of the polynomial.
Constraint: n1.

Optional Input Parameters

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

Output Parameters

1:     z2n – double array
The real and imaginary parts of the roots are stored in z1i and z2i respectively, for i=1,2,,n.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,a11=0.0 and a21=0.0,
orn<1.
   ifail=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 Further Comments.
   ifail=3
Either overflow or underflow prevents the evaluation of Pz near some of its zeros. This error is very unlikely to occur. If it does, please contact NAG. See also Further Comments.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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

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 b4p  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 nag_zeros_poly_complex (c02af) 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 function to locate the zeros of the polynomial dPcz for some suitable values of c and d. For example, if the original polynomial was Pz=2-100i+2100z20, then choosing c=2-10 and d=2100, for instance, would yield the scaled polynomial i+z20, which is well-behaved relative to overflow and underflow and has zeros which are 210 times those of Pz.
If the function 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 z1n  and z2n  contain the real and imaginary parts of the first root found, z1n-1  and z2n-1  contain the real and imaginary parts of the second root found, , z1 n- nR+1  and z2 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 / x02am×2 ).

Example

For this function two examples are presented. There is a single example program for nag_zeros_poly_complex (c02af), with a main program and the code to solve the two example problems given in the functions EX1 and EX2.
Example 1 (EX1)
This example finds the roots of the polynomial
a0 z5 + a1 z4 + a2 z3 + a3 z2 + a4 z+a5 = 0 ,  
where a0=5.0+6.0i , a1=30.0+20.0i , a2=- 0.2+6.0i , a3=50.0+100000.0i , a4=- 2.0-40.0i  and a5=10.0+1.0i .
Example 2 (EX2)
This example solves the same problem as function 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).
function c02af_example


fprintf('c02af example results\n\n');

n = int64(5);
a = [5, 30, -0.2,     50, -2, 10;
     6, 20, -6.0, 100000, 40,  1];

ex1(n,a);

ex2(n,a);



function ex1(n, a)
  % Compute the roots of the polynomial
  [z, ifail] = c02af(a, n);

  disp('Computed roots of polynomial:');
  cz = z(1,:) + i*z(2,:);
  disp(cz');

function ex2(n, a)
  % Compute the roots of the polynomial
  [z, ifail] = c02af(a, 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 j=1:2:n+1
    abar(:,j) = (1+epsbar)*abar(:,j);
  end
  for j=2:2:n+1
    abar(:,j) = (1-epsbar)*abar(:,j);
  end

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

  % Perform error analysis
  % Initialise markers to 0 (unmarked)
  m = zeros(n, 1);
  r = zeros(n, 1);
  rmax = x02al;
  
  cz = z(1,:) + i*z(2,:);
  czbar = zbar(1,:) + i*zbar(2,:);
  for j=1:n
    deltai = rmax;
    r1 = abs(cz(j));

    % Loop over all perturbed roots (stored in zbar)
    for k=1:n
      % Compare the current unperturbed root to all unmarked perturbed roots.
      if m(k) == 0
        r2 = abs(czbar(k));
        deltac = abs(r1-r2);
        
        if deltac < deltai
          deltai = deltac;
          jmin = k;
        end
      end
    end

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

    % Compute the relative error
    if r1 ~= 0
      r3 = abs(czbar(jmin));
      di = min(r1,r3);
      r(j) = max(deltai/max(di,deltai/rmax),x02aj);
    end

  end

  fprintf('\nComputed Roots of Polynomial   Error Estimate\n');
  fprintf('                              (machine dependent)\n');
  for j=1:n
    if (z(2,j)<0)
      fprintf('%9.4f - %7.4fi           %8.2e\n',z(1,j),-z(2,j),r(j));
    else
      fprintf('%9.4f + %7.4fi           %8.2e\n',z(1,j),z(2,j),r(j));
    end
  end
c02af example results

Computed roots of polynomial:
 -24.3278 + 4.8555i
   5.2487 -22.7359i
  14.6533 +16.5689i
  -0.0069 + 0.0074i
   0.0065 - 0.0074i


Computed Roots of Polynomial   Error Estimate
                              (machine dependent)
 -24.3278 -  4.8555i           1.43e-16
   5.2487 + 22.7359i           3.05e-16
  14.6533 - 16.5689i           3.21e-16
  -0.0069 -  0.0074i           1.71e-16
   0.0065 +  0.0074i           1.11e-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–2015