NAG Library Function Document

1Purpose

nag_cubic_roots (c02akc) determines the roots of a cubic equation with real coefficients.

2Specification

 #include #include
 void nag_cubic_roots (double u, double r, double s, double t, double zeror[], double zeroi[], double errest[], NagError *fail)

3Description

nag_cubic_roots (c02akc) attempts to find the roots of the cubic equation
 $uz3 + rz2 + sz + t = 0 ,$
where $u,r,s$ and $t$ are real coefficients with $u\ne 0$. The roots are located by finding the eigenvalues of the associated 3 by 3 (upper Hessenberg) companion matrix2 $H$ given by
 $H = 0 0 -t / u 1 0 -s / u 0 1 -r / u .$
Further details can be found in Section 9.
To obtain the roots of a quadratic equation, nag_quartic_roots (c02alc) can be used.
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

5Arguments

1:    $\mathbf{u}$doubleInput
On entry: $u$, the coefficient of ${z}^{3}$.
Constraint: ${\mathbf{u}}\ne 0.0$.
2:    $\mathbf{r}$doubleInput
On entry: $r$, the coefficient of ${z}^{2}$.
3:    $\mathbf{s}$doubleInput
On entry: $s$, the coefficient of $z$.
4:    $\mathbf{t}$doubleInput
On entry: $t$, the constant coefficient.
5:    $\mathbf{zeror}\left[3\right]$doubleOutput
6:    $\mathbf{zeroi}\left[3\right]$doubleOutput
On exit: ${\mathbf{zeror}}\left[i-1\right]$ and ${\mathbf{zeroi}}\left[i-1\right]$ contain the real and imaginary parts, respectively, of the $i$th root.
7:    $\mathbf{errest}\left[3\right]$doubleOutput
On exit: ${\mathbf{errest}}\left[i-1\right]$ contains an approximate error estimate for the $i$th root.
8:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6Error Indicators and Warnings

NE_C02_NOT_CONV
The iterative procedure used to determine the eigenvalues has failed to converge.
NE_C02_OVERFLOW
The companion matrix $H$ cannot be formed without overflow.
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.
NE_REAL
On entry, ${\mathbf{u}}=0.0$.
Constraint: ${\mathbf{u}}\ne 0.0$.

7Accuracy

If ${\mathbf{fail}}\mathbf{.}\mathbf{code}=\mathrm{NE_NOERROR}$ on exit, then the $i$th computed root should have approximately $\left|{\mathrm{log}}_{10}\left({\mathbf{errest}}\left[i-1\right]\right)\right|$ correct significant digits.

8Parallelism and Performance

nag_cubic_roots (c02akc) is not threaded in any implementation.

The method used by the function consists of the following steps, which are performed by functions from LAPACK.
 (a) Form $H$. (b) Apply a diagonal similarity transformation to $H$ (to give ${H}^{\prime }$). (c) Calculate the eigenvalues and Schur factorization of ${H}^{\prime }$. (d) Calculate the left and right eigenvectors of ${H}^{\prime }$. (e) Estimate reciprocal condition numbers for all the eigenvalues of ${H}^{\prime }$. (f) Calculate approximate error estimates for all the eigenvalues of ${H}^{\prime }$ (using the 1-norm).

10Example

To find the roots of the cubic equation
 $z 3 + 3 z 2 + 9 z - 13 = 0 .$

10.1Program Text

Program Text (c02akce.c)

10.2Program Data

Program Data (c02akce.d)

10.3Program Results

Program Results (c02akce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017