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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_complex_sqrt (a02aa)

## Purpose

nag_complex_sqrt (a02aa) evaluates the square root of the complex number x = (xr,xi)$x=\left({x}_{r},{x}_{i}\right)$.

## Syntax

[yr, yi] = a02aa(xr, xi)
[yr, yi] = nag_complex_sqrt(xr, xi)

## Description

The method of evaluating y = sqrt(x)$y=\sqrt{x}$ depends on the value of xr${x}_{r}$.
For xr0${x}_{r}\ge 0$,
 yr = sqrt((xr + sqrt(xr2 + xi2) )/2),  yi = (xi)/(2yr). $yr=xr+xr2+xi2 2, yi=xi2yr .$
For xr < 0${x}_{r}<0$,
 yi = sign(xi) × sqrt((|xr| + sqrt(xr2 + xi2) )/2) ,  yr = (xi)/(2yi). $yi=sign(xi)×|xr|+xr2+xi2 2 , yr=xi2yi .$
Overflow is avoided when squaring xi${x}_{i}$ and xr${x}_{r}$ by calling nag_complex_abs (a02ab) to evaluate sqrt(xr2 + xi2)$\sqrt{{x}_{r}^{2}+{x}_{i}^{2}}$.

## References

Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## Parameters

### Compulsory Input Parameters

1:     xr – double scalar
2:     xi – double scalar
xr${x}_{r}$ and xi${x}_{i}$, the real and imaginary parts of x$x$, respectively.

None.

None.

### Output Parameters

1:     yr – double scalar
2:     yi – double scalar
yr${y}_{r}$ and yi${y}_{i}$, the real and imaginary parts of y$y$, respectively.

None.

## Accuracy

The result should be correct to machine precision.

## Further Comments

The time taken by nag_complex_sqrt (a02aa) is negligible.

## Example

```function nag_complex_sqrt_example
xr = -1.7;
xi = 2.6;
[yr, yi] = nag_complex_sqrt(xr, xi)
```
```

yr =

0.8386

yi =

1.5502

```
```function a02aa_example
xr = -1.7;
xi = 2.6;
[yr, yi] = a02aa(xr, xi)
```
```

yr =

0.8386

yi =

1.5502

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013