PDF version (NAG web site
, 64-bit version, 64-bit version)
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
Description
nag_zeros_poly_real (c02ag) attempts to find all the roots of the
th degree real polynomial equation
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
where
and
is specified.
The sign in the denominator is chosen so that the modulus of the Laguerre step at , viz. , 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
, such that
and ensures that
‘roughly’ lies inside a circular region of radius
about
known to contain a zero of
; that is,
, where
denotes the Fejér bound (see
Marden (1966)) at the point
. Following
Smith (1967),
is taken to be
, where
is an upper bound for the magnitude of the smallest zero given by
is the zero
of smaller magnitude of the quadratic equation
and the Cauchy lower bound
for the smallest zero is computed (using Newton's Method) as the positive root of the polynomial equation
Starting from the origin, successive iterates are generated according to the rule
, for
, and
is ‘adjusted’ so that
and
. The iterative procedure terminates if
is smaller in absolute value than the bound on the rounding error in
and the current iterate
is taken to be a zero of (as is its conjugate
if is complex). The deflated polynomial
of degree if is real
( of degree if is complex) is then formed, and the above procedure is repeated on the deflated polynomial until , whereupon the remaining roots are obtained via the ‘standard’ closed formulae for a linear () or quadratic () 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 (
) and quartic (
) 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:
– double array
-
if
a is declared with bounds
, then
must contain
(i.e., the coefficient of
) , for
.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
, the degree of the polynomial.
Constraint:
.
Optional Input Parameters
- 1:
– logical scalar
Default:
Indicates whether or not the polynomial is to be scaled. See
Further Comments for advice on when it may be preferable to set
and for a description of the scaling strategy.
Output Parameters
- 1:
– double array
-
The real and imaginary parts of the roots are stored in
and
respectively, for
. Complex conjugate pairs of roots are stored in consecutive pairs of elements of
z; that is,
and
.
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
-
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.
-
-
Either overflow or underflow prevents the evaluation of
near some of its zeros. This error is very unlikely to occur. If it does, please contact
NAG. See also
Further Comments.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
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
, then a scaling factor for the coefficients is chosen as a power of the base
of the machine so that the largest coefficient in magnitude approaches
. You should note that no scaling is performed if the largest coefficient in magnitude exceeds
, even if
. (
,
and
are defined in
Chapter X02.)
However, with
, overflow may be encountered when the input coefficients
vary widely in magnitude, particularly on those machines for which
overflows. In such cases,
scal should be set to
false and the coefficients scaled so that the largest coefficient in magnitude does not exceed
.
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 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 for some suitable values of and . For example, if the original polynomial was , then choosing and , for instance, would yield the scaled polynomial , which is well-behaved relative to overflow and underflow and has zeros which are times those of .
If the function fails with
or
, 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
denote the number of roots found before the failure occurred. Then
and
contain the real and imaginary parts of the first root found,
and
contain the real and imaginary parts of the second root found,
and
contain the real and imaginary parts of the
th root found. After the failure has occurred, the remaining
elements of
z contain a large negative number (equal to
).
Example
For this function two examples are presented. There is a single example program for nag_zeros_poly_real (c02ag), 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 fifth degree polynomial
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).
Open in the MATLAB editor:
c02ag_example
function c02ag_example
fprintf('c02ag example results\n\n');
a = [1; 2; 3; 4; 5; 6];
n = int64(5);
ex1(n,a);
ex2(n,a);
function ex1(n,a)
[z, ifail] = c02ag(a, n);
disp('Computed roots of polynomial:');
cz = z(1,:) + i*z(2,:);
disp(cz');
function ex2(n,a)
[z, ifail] = c02ag(a, n);
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
[zbar, ifail] = c02ag(abar, int64(n));
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));
for k=1:n
if m(k) == 0
r2 = abs(czbar(k));
deltac = abs(r1-r2);
if deltac < deltai
deltai = deltac;
jmin = k;
end
end
end
m(jmin) = 1;
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
c02ag example results
Computed roots of polynomial:
-1.4918 + 0.0000i
0.5517 - 1.2533i
0.5517 + 1.2533i
-0.8058 - 1.2229i
-0.8058 + 1.2229i
Computed Roots of Polynomial Error Estimate
(machine dependent)
-1.4918 + 0.0000i 1.04e-15
0.5517 + 1.2533i 1.62e-16
0.5517 - 1.2533i 1.62e-16
-0.8058 + 1.2229i 1.52e-16
-0.8058 - 1.2229i 1.52e-16
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015