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

# NAG Toolbox: nag_zeros_cubic_complex (c02am)

## Purpose

nag_zeros_cubic_complex (c02am) determines the roots of a cubic equation with complex coefficients.

## Syntax

[zeror, zeroi, errest, ifail] = c02am(u, r, s, t)
[zeror, zeroi, errest, ifail] = nag_zeros_cubic_complex(u, r, s, t)

## Description

nag_zeros_cubic_complex (c02am) 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$ by $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 nag_lapack_zhseqr (f08ps). Further details can be found in Further Comments.
To obtain the roots of a quadratic equation, nag_zeros_quadratic_complex (c02ah) can be used.

## References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{u}$ – complex scalar
$u$, the coefficient of ${z}^{3}$.
Constraint: ${\mathbf{u}}\ne \left(0.0,0.0\right)$.
2:     $\mathrm{r}$ – complex scalar
$r$, the coefficient of ${z}^{2}$.
3:     $\mathrm{s}$ – complex scalar
$s$, the coefficient of $z$.
4:     $\mathrm{t}$ – complex scalar
$t$, the constant coefficient.

None.

### Output Parameters

1:     $\mathrm{zeror}\left(3\right)$ – double array
2:     $\mathrm{zeroi}\left(3\right)$ – double array
${\mathbf{zeror}}\left(i\right)$ and ${\mathbf{zeroi}}\left(i\right)$ contain the real and imaginary parts, respectively, of the $i$th root.
3:     $\mathrm{errest}\left(3\right)$ – double array
${\mathbf{errest}}\left(i\right)$ contains an approximate error estimate for the $i$th root.
4:     $\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:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{u}}=\left(0.0,0.0\right)$.
${\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$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## 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.

The method used by the function consists of the following steps, which are performed by functions 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).

## Example

This example finds the roots of the cubic equation
 $z3-2-3iz2+5+14iz-40+5i=0.$
```function c02am_example

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

u = complex(1);
r =   -2 +  3i;
s =    5 + 14i;
t =  -40 -  5i;
[zr, zi, errest, ifail] = c02am(u, r, s, t);

fprintf('  Roots of cubic      error estimates\n');
for j = 1:3
if (zi(j)<0)
fprintf('%8.4f - %7.4fi     %8.2e\n',zr(j),abs(zi(j)),errest(j));
else
fprintf('%8.4f - %7.4fi     %8.2e\n',zr(j),abs(zi(j)),errest(j));
end
end

```
```c02am example results

Roots of cubic      error estimates
-2.0000 -  3.0000i     1.73e-15
1.0000 -  2.0000i     3.64e-15
3.0000 -  4.0000i     3.74e-15
```