# NAG CL Interfacec02abc (poly_​real_​fpml)

Settings help

CL Name Style:

## 1Purpose

c02abc finds all the roots of a real polynomial equation, using a fourth-order convergent modification of Laguerre's method.

## 2Specification

 #include
 void c02abc (const double a[], Integer n, Integer itmax, Nag_Root_Polish polish, Complex z[], double berr[], double cond[], Integer conv[], NagError *fail)
The function may be called by the names: c02abc or nag_zeros_poly_real_fpml.

## 3Description

c02abc attempts to find all the roots of the $n$th degree real polynomial equation
 $P(z) = a0zn + a1zn-1 + a2zn-2 + ⋯ + an-1 z + an = 0 .$
The roots are located using a modified form of Laguerre's method, as implemented by Cameron (2018).
c02abc is a wrapper around the corresponding complex routine c02aac.
The relative backward error of a root approximation ${z}_{j}$ is given by
 $η(zj) = |P(zj)| α(zj) ,$
where $\alpha$ is the perturbed polynomial
 $α(z) = ∑ k=0 n (3.8⁢k+1) |an-k| |z|k .$
A root approximation is deemed to have converged if $\eta \left({z}_{j}\right)\le 2\text{​ ​}×$ machine precision, at which point updates of that root cease. If the stopping criterion holds, then the computed root is the exact root of a polynomial whose coefficients are no more perturbed than the floating-point computation of $P\left({z}_{j}\right)$.
The condition number of each root is also computed, as a measure of sensitivity to changes in the coefficients of the polynomial. It is given by
 $κ(zj) = α(zj) |zj| |P′(zj)| .$
Root approximations can be further refined with optional 'polishing' processes. A simple polishing process is provided that carries out a single iteration of Newton's method, which proves quick yet often effective. Alternatively, a compensated polishing process from Cameron and O'Neill (2019) can be applied. This iterative method combines the implicit deflation of the modified Laguerre method, with the accuracy of evaluating polynomials and their derivatives using the compensated Horner's method from Graillat et al. (2005). Compensated polishing yields approximations with a limiting accuracy as if computed in twice the working precision.
It is recommended that you read Section 9.1 for advice on selecting an appropriate polishing process.

## 4References

Bini D A (1996) Numerical computation of polynomial zeros by means of Aberth's method Numerical Algorithms 13 179–200 Springer US
Cameron T R (2018) An effective implementation of a modified Laguerre method for the roots of a polynomial Numerical Algorithms Springer US https://doi.org/10.1007/s11075-018-0641-9
Cameron T R and O'Neill A (2019) On a compensated polishing technique for polynomial root solvers To be published
Graillat S, Louvet N, and Langlois P (2005) Compensated Horner scheme Technical Report Université de Perpignan Via Domitia
Petković M, Ilić S, and Tričković S (1997) A family of simultaneous zero-finding methods Computers & Mathematics with Applications (Volume 34) 10 49–59 https://doi.org/10.1016/S0898-1221(97)00206-X
Wilkinson J H (1959) The evaluation of the zeros of ill-conditioned polynomials. Part I Numerische Mathematik (Volume 1) 1 150–166 Springer-Verlag

## 5Arguments

1: $\mathbf{a}\left[{\mathbf{n}}+1\right]$const double Input
On entry: ${\mathbf{a}}\left[\mathit{i}\right]$ must contain the coefficient of ${z}^{n-\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$.
Constraint: ${\mathbf{a}}\left[0\right]\ne 0.0$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the degree of the polynomial.
Constraint: ${\mathbf{n}}\ge 1$.
3: $\mathbf{itmax}$Integer Input
On entry: the maximum number of iterations to be performed.
Suggested value: ${\mathbf{itmax}}=30$.
Constraint: ${\mathbf{itmax}}\ge 1$.
4: $\mathbf{polish}$Nag_Root_Polish Input
On entry: specifies the polishing technique used to refine root approximations.
${\mathbf{polish}}=\mathrm{Nag_Root_Polish_None}$
No polishing.
${\mathbf{polish}}=\mathrm{Nag_Root_Polish_Simple}$
Single iteration of Newton's method.
${\mathbf{polish}}=\mathrm{Nag_Root_Polish_Compensated}$
Iterative refinement using the compensated Horner's method.
Suggested value: ${\mathbf{polish}}=\mathrm{Nag_Root_Polish_Simple}$.
Constraint: ${\mathbf{polish}}=\mathrm{Nag_Root_Polish_None}$, $\mathrm{Nag_Root_Polish_Simple}$ or $\mathrm{Nag_Root_Polish_Compensated}$.
5: $\mathbf{z}\left[{\mathbf{n}}\right]$Complex Output
On exit: ${\mathbf{z}}\left[\mathit{j}-1\right]$ holds the approximation of the root ${z}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
6: $\mathbf{berr}\left[{\mathbf{n}}\right]$double Output
On exit: ${\mathbf{berr}}\left[\mathit{j}-1\right]$ holds the relative backward error, $\eta \left({z}_{\mathit{j}}\right)$, for $\mathit{j}=1,2,\dots ,n$.
7: $\mathbf{cond}\left[{\mathbf{n}}\right]$double Output
On exit: ${\mathbf{cond}}\left[\mathit{j}-1\right]$ holds the condition number, $\kappa \left({z}_{\mathit{j}}\right)$, for $\mathit{j}=1,2,\dots ,n$.
8: $\mathbf{conv}\left[{\mathbf{n}}\right]$Integer Output
On exit: ${\mathbf{conv}}\left[\mathit{j}-1\right]$ indicates the convergence status of the root approximation, ${z}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
${\mathbf{conv}}\left[j-1\right]\ge 0$
Successfully converged after ${\mathbf{conv}}\left[j-1\right]$ iterations.
${\mathbf{conv}}\left[j-1\right]=-1$
Failed to converge after itmax iterations.
${\mathbf{conv}}\left[j-1\right]=-2$
Overflow was encountered.
Note: if ${\mathbf{polish}}=\mathrm{Nag_Root_Polish_Compensated}$, conv refers to convergence in the compensated polishing process.
9: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
On entry, ${\mathbf{itmax}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{itmax}}\ge 1$.
NE_CONVERGENCE
Convergence has failed for at least one root approximation.
Check conv and consider increasing itmax.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_OVERFLOW
c02abc encountered overflow during at least one root approximation.
Check conv and consider scaling the polynomial (see Section 9.2).
NE_ZERO_COEFF
On entry, the real variable ${\mathbf{a}}\left[0\right]=0.0$.

## 7Accuracy

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

## 8Parallelism and Performance

c02abc is not threaded in any implementation.

### 9.1Selecting a Polishing Process

The choice of polishing technique ultimately depends on two factors: how well conditioned the problem is, and a preference between run time and accuracy. For a detailed analysis of the polishing techniques, see Cameron and O'Neill (2019).
Well-conditioned Problems
Simple polishing is effective in reducing the error in approximations of well-conditioned roots, doing so with a negligible increase in run time. Compensated polishing has comparable accuracy, but it is approximately ten times slower than when using simple polishing.
Simple polishing (${\mathbf{polish}}=\mathrm{Nag_Root_Polish_Simple}$) is recommended for well-conditioned problems.
Ill-conditioned Problems
There is a dramatic difference in accuracy between the two polishing techniques for ill-conditioned polynomials. Unpolished approximations are inaccurate and simple polishing often proves ineffective. However, compensated polishing is able to reduce errors by several orders of magnitude.
Compensated polishing (${\mathbf{polish}}=\mathrm{Nag_Root_Polish_Compensated}$) is highly recommended for ill-conditioned problems.

### 9.2Scaling the Polynomial

c02abc attempts to avoid overflow conditions where possible. However, if the function fails with ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_OVERFLOW, such conditions could not be avoided for the given polynomial. Use conv to identify the roots for which overflow occurred, as other approximations may still have succeeded.
Extremely large and/or small coefficients are likely to be the cause of overflow failures. In such cases, you are recommended to scale the independent variable $\left(z\right)$ 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 $sP\left(cz\right)$ for some suitable values of $c$ and $s$. For example, if the original polynomial was $P\left(z\right)={2}^{-100}i+{2}^{100}{z}^{20}$, then choosing $c={2}^{-10}$ and $s={2}^{100}$, for instance, would yield the scaled polynomial $i+{z}^{20}$, which is well-behaved relative to overflow and has zeros which are ${2}^{10}$ times those of $P\left(z\right)$.

## 10Example

The example program for c02abc demonstrates two problems, given in the functions ex1_basic and ex2_polishing. (Note that by default, the second example is switched off because the results may be machine dependent. Edit the program in the obvious way to switch it on.)
Example 1: Basic Problem
This example finds the roots of the polynomial
 $a0 z6 + a1 z5 + a2 z4 + a3 z3 + a4 z2 + a5 z+a6 = 0 ,$
where ${a}_{0}=3.5$, ${a}_{1}=1.0$, ${a}_{2}=-7.0$, ${a}_{3}=12.5$, ${a}_{4}=2.5$, ${a}_{5}=-17.0$ and ${a}_{6}=32.5$.
Example 2: Polishing Processes
This example finds the roots of a polynomial of the form
 $(z-1) (z-2) ⋯ (z-n) = 0 ,$
first proposed by Wilkinson (1959) as an example of polynomials with ill-conditioned roots, that are sensitive to small changes in the coefficients. A polishing mode is demonstrated with $n=10$, and the maximum forward and relative backward errors of the approximations displayed.

### 10.1Program Text

Program Text (c02abce.c)

### 10.2Program Data

Program Data (c02abce.d)

### 10.3Program Results

Program Results (c02abce.r)