Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

## Purpose

nag_zeros_quadratic_complex (c02ah) determines the roots of a quadratic equation with complex coefficients.

## Syntax

[zsm, zlg, ifail] = c02ah(ar, ai, br, bi, cr, ci)
[zsm, zlg, ifail] = nag_zeros_quadratic_complex(ar, ai, br, bi, cr, ci)

## Description

nag_zeros_quadratic_complex (c02ah) 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 function CQDRTC from Smith (1967).
Note:  it is not necessary to scale the coefficients prior to calling the function.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{ar}$ – double scalar
2:     $\mathrm{ai}$ – double scalar
ar and ai must contain the real and imaginary parts respectively of $a$, the coefficient of ${z}^{2}$.
3:     $\mathrm{br}$ – double scalar
4:     $\mathrm{bi}$ – double scalar
br and bi must contain the real and imaginary parts respectively of $b$, the coefficient of $z$.
5:     $\mathrm{cr}$ – double scalar
6:     $\mathrm{ci}$ – double scalar
cr and ci must contain the real and imaginary parts respectively of $c$, the constant coefficient.

None.

### Output Parameters

1:     $\mathrm{zsm}\left(2\right)$ – double array
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.
2:     $\mathrm{zlg}\left(2\right)$ – double array
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.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W  ${\mathbf{ifail}}=1$
On entry, $\left({\mathbf{ar}},{\mathbf{ai}}\right)=\left(0,0\right)$. In this case, ${\mathbf{zsm}}\left(1\right)$ and ${\mathbf{zsm}}\left(2\right)$ contain the real and imaginary parts respectively of the root $-c/b$.
${\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)$. In this case, ${\mathbf{zsm}}\left(1\right)$ contains the largest machine representable number (see nag_machine_real_largest (x02al)) and ${\mathbf{zsm}}\left(2\right)$ contains zero.
${\mathbf{ifail}}=3$
On entry, $\left({\mathbf{ar}},{\mathbf{ai}}\right)=\left(0,0\right)$ and the root $-c/b$ overflows. In this case, ${\mathbf{zsm}}\left(1\right)$ contains the largest machine representable number (see nag_machine_real_largest (x02al)) and ${\mathbf{zsm}}\left(2\right)$ contains zero.
${\mathbf{ifail}}=4$
On entry, $\left({\mathbf{cr}},{\mathbf{ci}}\right)=\left(0,0\right)$ and the root $-b/a$ overflows. In this case, both ${\mathbf{zsm}}\left(1\right)$ and ${\mathbf{zsm}}\left(2\right)$ contain zero.
${\mathbf{ifail}}=5$
On entry, $\stackrel{~}{b}$ is so large that ${\stackrel{~}{b}}^{2}$ is indistinguishable from ${\stackrel{~}{b}}^{2}-4\stackrel{~}{a}\stackrel{~}{c}$ and the root $-b/a$ overflows, where $\stackrel{~}{b}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left|{\mathbf{br}}\right|,\left|{\mathbf{bi}}\right|\right)$, $\stackrel{~}{a}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left|{\mathbf{ar}}\right|,\left|{\mathbf{ai}}\right|\right)$ and $\stackrel{~}{c}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left|{\mathbf{cr}}\right|,\left|{\mathbf{ci}}\right|\right)$. In this case, ${\mathbf{zsm}}\left(1\right)$ and ${\mathbf{zsm}}\left(2\right)$ contain the real and imaginary parts respectively of the root $-c/b$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
If ${\mathbf{ifail}}>{\mathbf{0}}$ on exit, then ${\mathbf{zlg}}\left(1\right)$ contains the largest machine representable number (see nag_machine_real_largest (x02al)) and ${\mathbf{zlg}}\left(2\right)$ contains zero.

## Accuracy

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.

None.

## Example

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$.
```function c02ah_example

fprintf('c02ah example results\n\n');

ar =  1;  ai = 0;
br = -3;  bi = 1;
cr =  8;  ci = 1;
[zsm, zlg, ifail] = c02ah(ar, ai, br, bi, cr, ci);

z(1) = zsm(1) + i*zsm(2);
z(2) = zlg(1) + i*zlg(2);
disp(z');

```
```c02ah example results