## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

c02ahf determines the roots of a quadratic equation with complex coefficients.

## 2Specification

Fortran Interface
 Subroutine c02ahf ( ar, ai, br, bi, cr, ci, zsm, zlg,
 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: ar, ai, br, bi, cr, ci Real (Kind=nag_wp), Intent (Out) :: zsm(2), zlg(2)
#include <nag.h>
 void c02ahf_ (const double *ar, const double *ai, const double *br, const double *bi, const double *cr, const double *ci, double zsm[], double zlg[], Integer *ifail)
The routine may be called by the names c02ahf or nagf_zeros_quadratic_complex.

## 3Description

c02ahf attempts to find the roots of the quadratic equation $a{z}^{2}+bz+c=0$ (where $a$, $b$ and $c$ are complex coefficients), by carefully evaluating the ‘standard’ closed formula
 $z=-b±b2-4ac 2a .$
It is based on the routine CQDRTC from Smith (1967).
Note:  it is not necessary to scale the coefficients prior to calling the routine.

## 4References

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

## 5Arguments

1: $\mathbf{ar}$Real (Kind=nag_wp) Input
2: $\mathbf{ai}$Real (Kind=nag_wp) Input
On entry: ar and ai must contain the real and imaginary parts respectively of $a$, the coefficient of ${z}^{2}$.
3: $\mathbf{br}$Real (Kind=nag_wp) Input
4: $\mathbf{bi}$Real (Kind=nag_wp) Input
On entry: br and bi must contain the real and imaginary parts respectively of $b$, the coefficient of $z$.
5: $\mathbf{cr}$Real (Kind=nag_wp) Input
6: $\mathbf{ci}$Real (Kind=nag_wp) Input
On entry: cr and ci must contain the real and imaginary parts respectively of $c$, the constant coefficient.
7: $\mathbf{zsm}\left(2\right)$Real (Kind=nag_wp) array Output
On exit: the real and imaginary parts of the smallest root in magnitude are stored in ${\mathbf{zsm}}\left(1\right)$ and ${\mathbf{zsm}}\left(2\right)$ respectively.
8: $\mathbf{zlg}\left(2\right)$Real (Kind=nag_wp) array Output
On exit: the real and imaginary parts of the largest root in magnitude are stored in ${\mathbf{zlg}}\left(1\right)$ and ${\mathbf{zlg}}\left(2\right)$ respectively.
9: $\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:
Note: if ${\mathbf{ifail}}>{\mathbf{0}}$ on exit, then ${\mathbf{zlg}}\left(1\right)$ contains the largest machine representable number (see x02alf) and ${\mathbf{zlg}}\left(2\right)$ contains zero.
${\mathbf{ifail}}=1$
On entry, $\left({\mathbf{ar}},{\mathbf{ai}}\right)=\left(0,0\right)$.
${\mathbf{ifail}}=2$
On entry, $\left({\mathbf{ar}},{\mathbf{ai}}\right)=\left(0,0\right)$ and $\left({\mathbf{br}},{\mathbf{bi}}\right)=\left(0,0\right)$.
${\mathbf{ifail}}=3$
On entry, $\left({\mathbf{ar}},{\mathbf{ai}}\right)=\left(0,0\right)$ and the root $-\left({\mathbf{cr}},{\mathbf{ci}}\right)/\left({\mathbf{br}},{\mathbf{bi}}\right)$ overflows: ${\mathbf{ar}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{cr}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{br}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{ai}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{ci}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{bi}}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=4$
On entry, $\left({\mathbf{cr}},{\mathbf{ci}}\right)=\left(0,0\right)$ and the root $-\left({\mathbf{br}},{\mathbf{bi}}\right)/\left({\mathbf{ar}},{\mathbf{ai}}\right)$ overflows: ${\mathbf{cr}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{br}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{ar}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{ci}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{bi}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ai}}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=5$
On entry, $B$ is so large that ${B}^{2}$ is indistinguishable from $\left({B}^{2}-4×A×C\right)$ and the root $-\left({\mathbf{br}},{\mathbf{bi}}\right)/\left({\mathbf{ar}},{\mathbf{ai}}\right)$ overflows: $B=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(|{\mathbf{br}}|,|{\mathbf{bi}}|\right)=⟨\mathit{\text{value}}⟩$, $A=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(|{\mathbf{ar}}|,|{\mathbf{ai}}|\right)=⟨\mathit{\text{value}}⟩$, $C=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(|{\mathbf{cr}}|,|{\mathbf{ci}}|\right)=⟨\mathit{\text{value}}⟩$, ${\mathbf{br}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{bi}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{ar}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ai}}=⟨\mathit{\text{value}}⟩$.
${\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 computed roots should be accurate to within a small multiple of the machine precision except when underflow (or overflow) occurs, in which case the true roots are within a small multiple of the underflow (or overflow) threshold of the machine.

## 8Parallelism and Performance

c02ahf is not threaded in any implementation.

None.

## 10Example

This example finds the roots of the quadratic equation ${z}^{2}-\left(3.0-1.0i\right)z+\left(8.0+1.0i\right)=0$.

### 10.1Program Text

Program Text (c02ahfe.f90)

### 10.2Program Data

Program Data (c02ahfe.d)

### 10.3Program Results

Program Results (c02ahfe.r)