# NAG FL Interfacec02amf (cubic_​complex)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

c02amf determines the roots of a cubic equation with complex coefficients.

## 2Specification

Fortran Interface
 Subroutine c02amf ( u, r, s, t,
 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (Out) :: zeror(3), zeroi(3), errest(3) Complex (Kind=nag_wp), Intent (In) :: u, r, s, t
#include <nag.h>
 void c02amf_ (const Complex *u, const Complex *r, const Complex *s, const Complex *t, double zeror[], double zeroi[], double errest[], Integer *ifail)
The routine may be called by the names c02amf or nagf_zeros_cubic_complex.

## 3Description

c02amf attempts to find the roots of the cubic equation
 $uz3+rz2+sz+t=0,$
where $u$, $r$, $s$ and $t$ are complex coefficients with $u\ne 0$. The roots are located by finding the eigenvalues of the associated $3×3$ (upper Hessenberg) companion matrix $H$ given by
 $H= ( 0 0 -t/u 1 0 -s/u 0 1 -r/u ) .$
The eigenvalues are obtained by a call to f08psf. Further details can be found in Section 9.
To obtain the roots of a quadratic equation, c02ahf 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}$Complex (Kind=nag_wp) Input
On entry: $u$, the coefficient of ${z}^{3}$.
Constraint: ${\mathbf{u}}\ne \left(0.0,0.0\right)$.
2: $\mathbf{r}$Complex (Kind=nag_wp) Input
On entry: $r$, the coefficient of ${z}^{2}$.
3: $\mathbf{s}$Complex (Kind=nag_wp) Input
On entry: $s$, the coefficient of $z$.
4: $\mathbf{t}$Complex (Kind=nag_wp) Input
On entry: $t$, the constant coefficient.
5: $\mathbf{zeror}\left(3\right)$Real (Kind=nag_wp) array Output
6: $\mathbf{zeroi}\left(3\right)$Real (Kind=nag_wp) array Output
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.
7: $\mathbf{errest}\left(3\right)$Real (Kind=nag_wp) array Output
On exit: ${\mathbf{errest}}\left(i\right)$ contains an approximate error estimate for the $i$th root.
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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{u}}=\left(0.0,0.0\right)$.
Constraint: ${\mathbf{u}}\ne \left(0.0,0.0\right)$
${\mathbf{ifail}}=2$
The companion matrix $H$ cannot be formed without overflow.
${\mathbf{ifail}}=3$
Failure to converge in f08psf.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

c02amf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
c02amf 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.
1. (a)Form matrix $H$.
2. (b)Apply a diagonal similarity transformation to $H$ (to give ${H}^{\prime }$).
3. (c)Calculate the eigenvalues and Schur factorization of ${H}^{\prime }$.
4. (d)Calculate the left and right eigenvectors of ${H}^{\prime }$.
5. (e)Estimate reciprocal condition numbers for all the eigenvalues of ${H}^{\prime }$.
6. (f)Calculate approximate error estimates for all the eigenvalues of ${H}^{\prime }$ (using the $1$-norm).

### 9.1Internal Changes

Internal changes have been made to this routine as follows:
• At Mark 27.1: The algorithm used by this routine was adapted to make direct use of complex data.
For details of all known issues which have been reported for the NAG Library please refer to the Known Issues.

## 10Example

This example finds the roots of the cubic equation
 $z3-(2-3i)z2+(5+14i)z-(40+5i)=0.$

### 10.1Program Text

Program Text (c02amfe.f90)

### 10.2Program Data

Program Data (c02amfe.d)

### 10.3Program Results

Program Results (c02amfe.r)