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_zeros_quadratic_complex (c02ah)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_zeros_quadratic_complex (c02ah) determines the roots of a quadratic equation with complex coefficients.

Syntax

[zsm, zlg, ifail] = c02ah(ar, ai, br, bi, cr, ci)
[zsm, zlg, ifail] = nag_zeros_quadratic_complex(ar, ai, br, bi, cr, ci)

Description

nag_zeros_quadratic_complex (c02ah) attempts to find the roots of the quadratic equation az2+bz+c=0 (where a, b and c are complex coefficients), by carefully evaluating the ‘standard’ closed formula
z=-b±b2-4ac 2a .  
It is based on the function CQDRTC 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:     ar – double scalar
2:     ai – double scalar
ar and ai must contain the real and imaginary parts respectively of a, the coefficient of z2.
3:     br – double scalar
4:     bi – double scalar
br and bi must contain the real and imaginary parts respectively of b, the coefficient of z.
5:     cr – double scalar
6:     ci – double scalar
cr and ci must contain the real and imaginary parts respectively of c, the constant coefficient.

Optional Input Parameters

None.

Output Parameters

1:     zsm2 – double array
The real and imaginary parts of the smallest root in magnitude are stored in zsm1 and zsm2 respectively.
2:     zlg2 – double array
The real and imaginary parts of the largest root in magnitude are stored in zlg1 and zlg2 respectively.
3:     ifail int64int32nag_int scalar
ifail=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
On entry, ar,ai=0,0. In this case, zsm1 and zsm2 contain the real and imaginary parts respectively of the root -c/b.
   ifail=2
On entry, ar,ai=0,0 and br,bi=0,0. In this case, zsm1 contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zsm2 contains zero.
   ifail=3
On entry, ar,ai=0,0 and the root -c/b overflows. In this case, zsm1 contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zsm2 contains zero.
   ifail=4
On entry, cr,ci=0,0 and the root -b/a overflows. In this case, both zsm1 and zsm2 contain zero.
   ifail=5
On entry, b~  is so large that b~ 2  is indistinguishable from b~ 2 - 4 a~ c~  and the root -b / a  overflows, where b~ = maxbr,bi , a~ = maxar,ai  and c~ = maxcr,ci . In this case, zsm1 and zsm2 contain the real and imaginary parts respectively of the root -c / b .
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.
If ifail>0 on exit, then zlg1 contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zlg2 contains zero.

Accuracy

If ifail=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.

Further Comments

None.

Example

This example finds the roots of the quadratic equation z2-3.0-1.0i z+8.0+1.0i=0.
function c02ah_example


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

ar =  1;  ai = 0;
br = -3;  bi = 1;
cr =  8;  ci = 1;
[zsm, zlg, ifail] = c02ah(ar, ai, br, bi, cr, ci);

disp('Roots of the quadratic equation:');
z(1) = zsm(1) + i*zsm(2);
z(2) = zlg(1) + i*zlg(2);
disp(z');


c02ah example results

Roots of the quadratic equation:
   1.0000 - 2.0000i
   2.0000 + 3.0000i


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