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_real (c02aj) determines the roots of a quadratic equation with real coefficients.

## Syntax

[zsm, zlg, ifail] = c02aj(a, b, c)
[zsm, zlg, ifail] = nag_zeros_quadratic_real(a, b, c)

## Description

nag_zeros_quadratic_real (c02aj) attempts to find the roots of the quadratic equation az2 + bz + c = 0$a{z}^{2}+bz+c=0$ (where a$a$, b$b$ and c$c$ are real coefficients), by carefully evaluating the ‘standard’ closed formula
 z = ( − b ± sqrt(b2 − 4ac))/(2a). $z=-b±b2-4ac 2a .$
It is based on the function QDRTC 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:     a – double scalar
Must contain a$a$, the coefficient of z2${z}^{2}$.
2:     b – double scalar
Must contain b$b$, the coefficient of z$z$.
3:     c – double scalar
Must contain c$c$, the constant coefficient.

None.

None.

### Output Parameters

1:     zsm(2$2$) – double array
The real and imaginary parts of the smallest root in magnitude are stored in zsm(1)${\mathbf{zsm}}\left(1\right)$ and zsm(2)${\mathbf{zsm}}\left(2\right)$ respectively.
2:     zlg(2$2$) – double array
The real and imaginary parts of the largest root in magnitude are stored in zlg(1)${\mathbf{zlg}}\left(1\right)$ and zlg(2)${\mathbf{zlg}}\left(2\right)$ respectively.
3:     ifail – int64int32nag_int scalar
${\mathrm{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 ifail = 1${\mathbf{ifail}}=1$
On entry, a = 0.0${\mathbf{a}}=0.0$. In this case, zsm(1)${\mathbf{zsm}}\left(1\right)$ contains the root c / b$-c/b$ and zsm(2)${\mathbf{zsm}}\left(2\right)$ contains zero.
ifail = 2${\mathbf{ifail}}=2$
On entry, a = 0.0${\mathbf{a}}=0.0$ and b = 0.0${\mathbf{b}}=0.0$. In this case, zsm(1)${\mathbf{zsm}}\left(1\right)$ contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zsm(2)${\mathbf{zsm}}\left(2\right)$ contains zero.
ifail = 3${\mathbf{ifail}}=3$
On entry, a = 0.0${\mathbf{a}}=0.0$ and the root c / b$-c/b$ overflows. In this case, zsm(1)${\mathbf{zsm}}\left(1\right)$ contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zsm(2)${\mathbf{zsm}}\left(2\right)$ contains zero.
ifail = 4${\mathbf{ifail}}=4$
On entry, c = 0.0${\mathbf{c}}=0.0$ and the root b / a$-b/a$ overflows. In this case, both zsm(1)${\mathbf{zsm}}\left(1\right)$ and zsm(2)${\mathbf{zsm}}\left(2\right)$ contain zero.
ifail = 5${\mathbf{ifail}}=5$
On entry, b$b$ is so large that b2${b}^{2}$ is indistinguishable from b24ac${b}^{2}-4ac$ and the root b / a$-b/a$ overflows. In this case, zsm(1)${\mathbf{zsm}}\left(1\right)$ contains the root c / b$-c/b$ and zsm(2)${\mathbf{zsm}}\left(2\right)$ contains zero.
If ${\mathbf{ifail}}>{\mathbf{0}}$ on exit, then zlg(1)${\mathbf{zlg}}\left(1\right)$ contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zlg(2)${\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

```function nag_zeros_quadratic_real_example
a = 1;
b = 3;
c = -10;
[zsm, zlg, ifail] = nag_zeros_quadratic_real(a, b, c)
```
```

zsm =

2
0

zlg =

-5
0

ifail =

0

```
```function c02aj_example
a = 1;
b = 3;
c = -10;
[zsm, zlg, ifail] = c02aj(a, b, c)
```
```

zsm =

2
0

zlg =

-5
0

ifail =

0

```