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_real (c02aj)

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 = 0az2+bz+c=0 (where aa, bb and cc are real coefficients), by carefully evaluating the ‘standard’ closed formula
z = (b ± sqrt(b24ac))/(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 aa, the coefficient of z2z2.
2:     b – double scalar
Must contain bb, the coefficient of zz.
3:     c – double scalar
Must contain cc, the constant coefficient.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     zsm(22) – double array
The real and imaginary parts of the smallest root in magnitude are stored in zsm(1)zsm1 and zsm(2)zsm2 respectively.
2:     zlg(22) – double array
The real and imaginary parts of the largest root in magnitude are stored in zlg(1)zlg1 and zlg(2)zlg2 respectively.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry, a = 0.0a=0.0. In this case, zsm(1)zsm1 contains the root c / b-c/b and zsm(2)zsm2 contains zero.
  ifail = 2ifail=2
On entry, a = 0.0a=0.0 and b = 0.0b=0.0. In this case, zsm(1)zsm1 contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zsm(2)zsm2 contains zero.
  ifail = 3ifail=3
On entry, a = 0.0a=0.0 and the root c / b-c/b overflows. In this case, zsm(1)zsm1 contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zsm(2)zsm2 contains zero.
  ifail = 4ifail=4
On entry, c = 0.0c=0.0 and the root b / a-b/a overflows. In this case, both zsm(1)zsm1 and zsm(2)zsm2 contain zero.
  ifail = 5ifail=5
On entry, bb is so large that b2b2 is indistinguishable from b24acb2-4ac and the root b / a-b/a overflows. In this case, zsm(1)zsm1 contains the root c / b-c/b and zsm(2)zsm2 contains zero.
If ifail > 0ifail>0 on exit, then zlg(1)zlg1 contains the largest machine representable number (see nag_machine_real_largest (x02al)) and zlg(2)zlg2 contains zero.

Accuracy

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

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



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