C02 Chapter Contents
C02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentC02ALF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

C02ALF determines the roots of a quartic equation with real coefficients.

## 2  Specification

 SUBROUTINE C02ALF ( E, A, B, C, D, ZEROR, ZEROI, ERREST, IFAIL)
 INTEGER IFAIL REAL (KIND=nag_wp) E, A, B, C, D, ZEROR(4), ZEROI(4), ERREST(4)

## 3  Description

C02ALF attempts to find the roots of the quartic equation
 $ez4+az3+bz2+cz+d=0,$
where $e$, $a$, $b$, $c$ and $d$ are real coefficients with $e\ne 0$. The roots are located by finding the eigenvalues of the associated $4$ by $4$ (upper Hessenberg) companion matrix $H$ given by
 $H= 0 0 0 -d/e 1 0 0 -c/e 0 1 0 -b/e 0 0 1 -a/e .$
The eigenvalues are obtained by a call to F08PEF (DHSEQR). Further details can be found in Section 9.
To obtain the roots of a cubic equation, C02AKF can be used.
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5  Parameters

1:     $\mathrm{E}$ – REAL (KIND=nag_wp)Input
On entry: $e$, the coefficient of ${z}^{4}$.
Constraint: ${\mathbf{E}}\ne 0.0$.
2:     $\mathrm{A}$ – REAL (KIND=nag_wp)Input
On entry: $a$, the coefficient of ${z}^{3}$.
3:     $\mathrm{B}$ – REAL (KIND=nag_wp)Input
On entry: $b$, the coefficient of ${z}^{2}$.
4:     $\mathrm{C}$ – REAL (KIND=nag_wp)Input
On entry: $c$, the coefficient of $z$.
5:     $\mathrm{D}$ – REAL (KIND=nag_wp)Input
On entry: $d$, the constant coefficient.
6:     $\mathrm{ZEROR}\left(4\right)$ – REAL (KIND=nag_wp) arrayOutput
7:     $\mathrm{ZEROI}\left(4\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{ZEROR}}\left(i\right)$ and ${\mathbf{ZEROI}}\left(i\right)$ contain the real and imaginary parts, respectively, of the $i$th root.
8:     $\mathrm{ERREST}\left(4\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{ERREST}}\left(i\right)$ contains an approximate error estimate for the $i$th root.
9:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{E}}=0.0$.
${\mathbf{IFAIL}}=2$
The companion matrix $H$ cannot be formed without overflow.
${\mathbf{IFAIL}}=3$
The iterative procedure used to determine the eigenvalues has failed to converge.
${\mathbf{IFAIL}}=-99$
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

## 7  Accuracy

If ${\mathbf{IFAIL}}={\mathbf{0}}$ on exit, then the $i$th computed root should have approximately $\left|{\mathrm{log}}_{10}\left({\mathbf{ERREST}}\left(i\right)\right)\right|$ correct significant digits.

## 8  Parallelism and Performance

C02ALF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
C02ALF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The method used by the routine consists of the following steps, which are performed by routines from LAPACK in Chapter F08.
 (a) Form matrix $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).

## 10  Example

This example finds the roots of the quartic equation
 $z4+2⁢z3+6⁢z2-8z-40=0.$

### 10.1  Program Text

Program Text (c02alfe.f90)

### 10.2  Program Data

Program Data (c02alfe.d)

### 10.3  Program Results

Program Results (c02alfe.r)