hide long namesshow long names
hide short namesshow short names
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=(xr,xi).

Syntax

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

Description

The method of evaluating y = sqrt(x)y=x depends on the value of xrxr.
For xr0xr0,
yr = sqrt((xr + sqrt(xr2 + xi2) )/2),  yi = (xi)/(2yr).
yr=xr+xr2+xi2 2,  yi=xi2yr .
For xr < 0xr<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 xixi and xrxr by calling nag_complex_abs (a02ab) to evaluate sqrt(xr2 + xi2)xr2+xi2.

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
xrxr and xixi, the real and imaginary parts of xx, respectively.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     yr – double scalar
2:     yi – double scalar
yryr and yiyi, the real and imaginary parts of yy, respectively.

Error Indicators and Warnings

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