C02AJF (PDF version)
C02 Chapter Contents
C02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

C02AJF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

C02AJF determines the roots of a quadratic equation with real coefficients.

2  Specification

SUBROUTINE C02AJF ( A, B, C, ZSM, ZLG, IFAIL)
INTEGER  IFAIL
REAL (KIND=nag_wp)  A, B, C, ZSM(2), ZLG(2)

3  Description

C02AJF attempts to find the roots of the quadratic equation az2+bz+c=0 (where a, b and c are real coefficients), by carefully evaluating the ‘standard’ closed formula
z=-b±b2-4ac 2a .  
It is based on the routine QDRTC from Smith (1967).
Note:  it is not necessary to scale the coefficients prior to calling the routine.

4  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

5  Parameters

1:     A – REAL (KIND=nag_wp)Input
On entry: must contain a, the coefficient of z2.
2:     B – REAL (KIND=nag_wp)Input
On entry: must contain b, the coefficient of z.
3:     C – REAL (KIND=nag_wp)Input
On entry: must contain c, the constant coefficient.
4:     ZSM2 – REAL (KIND=nag_wp) arrayOutput
On exit: the real and imaginary parts of the smallest root in magnitude are stored in ZSM1 and ZSM2 respectively.
5:     ZLG2 – REAL (KIND=nag_wp) arrayOutput
On exit: the real and imaginary parts of the largest root in magnitude are stored in ZLG1 and ZLG2 respectively.
6:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry, A=0.0. In this case, ZSM1 contains the root -c/b and ZSM2 contains zero.
IFAIL=2
On entry, A=0.0 and B=0.0. In this case, ZSM1 contains the largest machine representable number (see X02ALF) and ZSM2 contains zero.
IFAIL=3
On entry, A=0.0 and the root -c/b overflows. In this case, ZSM1 contains the largest machine representable number (see X02ALF) and ZSM2 contains zero.
IFAIL=4
On entry, C=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 b2 is indistinguishable from b2-4ac and the root -b/a overflows. In this case, ZSM1 contains the root -c/b and ZSM2 contains zero.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.
If IFAIL>0 on exit, then ZLG1 contains the largest machine representable number (see X02ALF) and ZLG2 contains zero.

7  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.

8  Parallelism and Performance

Not applicable.

9  Further Comments

None.

10  Example

This example finds the roots of the quadratic equation z2+3z-10=0.

10.1  Program Text

Program Text (c02ajfe.f90)

10.2  Program Data

Program Data (c02ajfe.d)

10.3  Program Results

Program Results (c02ajfe.r)


C02AJF (PDF version)
C02 Chapter Contents
C02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015