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)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_complex_sqrt (a02aa) evaluates the square root of the complex number x=xr,xi.

Syntax

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

Description

The method of evaluating y=x depends on the value of xr.
For xr0,
yr=xr+xr2+xi2 2,  yi=xi2yr .  
For xr<0,
yi=signxi×xr+xr2+xi2 2 ,  yr=xi2yi .  
Overflow is avoided when squaring xi and xr by calling nag_complex_abs (a02ab) to evaluate 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
xr and xi, the real and imaginary parts of x, respectively.

Optional Input Parameters

None.

Output Parameters

1:     yr – double scalar
2:     yi – double scalar
yr and yi, the real and imaginary parts of y, 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

This example finds the square root of -1.7+2.6i.
function a02aa_example


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

xr = -1.7;
xi = 2.6;
x  = xr + i*xi;

[yr, yi] = a02aa(xr, xi);
y = yr+i*yi;
fprintf('The square root of ');
disp(x);
fprintf('                is ');
disp(y);


a02aa example results

The square root of   -1.7000 + 2.6000i

                is    0.8386 + 1.5502i


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–2015