C02AHF (pdf version)
Chapter Contents
Chapter Introduction
NAG Library Manual

NAG Fortran Library Routine Document

C02AHF

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

C02AHF determines the roots of a quadratic equation with complex coefficients.

2  Specification

SUBROUTINE C02AHF (AR, AI, BR, BI, CR, CI, ZSM, ZLG, IFAIL)
INTEGERIFAIL
double precisionAR, AI, BR, BI, CR, CI, ZSM(2), ZLG(2)

3  Description

C02AHF 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 routine CQDRTC 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:     AR – double precisionInput
2:     AI – double precisionInput
On entry: AR and AI must contain the real and imaginary parts respectively of a, the coefficient of z2.
3:     BR – double precisionInput
4:     BI – double precisionInput
On entry: BR and BI must contain the real and imaginary parts respectively of b, the coefficient of z.
5:     CR – double precisionInput
6:     CI – double precisionInput
On entry: CR and CI must contain the real and imaginary parts respectively of c, the constant coefficient.
7:     ZSM(2) – double precision arrayOutput
8:     ZLG(2) – double precision arrayOutput
9:     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 Chapter P01 for details.
On exit: IFAIL =0 unless the routine detects an error (see Section 6).
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.

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, AR,AI=0,0. In this case, ZSM1 and ZSM2  contain the real and imaginary parts respectively of the root -c/b.
IFAIL = 2
IFAIL = 3
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 .
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  Further Comments

None.

9  Example

To find the roots of the quadratic equation z2-3.0-1.0i z+8.0+1.0i=0.

9.1  Program Text

Program Text (c02ahfe.f)

9.2  Program Data

Program Data (c02ahfe.d)

9.3  Program Results

Program Results (c02ahfe.r)


C02AHF (pdf version)
Chapter Contents
Chapter Introduction
NAG Library Manual

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