NAG FL Interface
c02ahf (quadratic_​complex)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

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

2 Specification

Fortran Interface
Subroutine c02ahf ( ar, ai, br, bi, cr, ci, zsm, zlg, ifail)
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: ar, ai, br, bi, cr, ci
Real (Kind=nag_wp), Intent (Out) :: zsm(2), zlg(2)
C Header Interface
#include <nag.h>
void  c02ahf_ (const double *ar, const double *ai, const double *br, const double *bi, const double *cr, const double *ci, double zsm[], double zlg[], Integer *ifail)
The routine may be called by the names c02ahf or nagf_zeros_quadratic_complex.

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 Arguments

1: ar Real (Kind=nag_wp) Input
2: ai Real (Kind=nag_wp) Input
On entry: ar and ai must contain the real and imaginary parts respectively of a, the coefficient of z2.
3: br Real (Kind=nag_wp) Input
4: bi Real (Kind=nag_wp) Input
On entry: br and bi must contain the real and imaginary parts respectively of b, the coefficient of z.
5: cr Real (Kind=nag_wp) Input
6: ci Real (Kind=nag_wp) Input
On entry: cr and ci must contain the real and imaginary parts respectively of c, the constant coefficient.
7: zsm(2) Real (Kind=nag_wp) array Output
On exit: the real and imaginary parts of the smallest root in magnitude are stored in zsm(1) and zsm(2) respectively.
8: zlg(2) Real (Kind=nag_wp) array Output
On exit: the real and imaginary parts of the largest root in magnitude are stored in zlg(1) and zlg(2) respectively.
9: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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:
Note: if ifail>0 on exit, then zlg(1) contains the largest machine representable number (see x02alf) and zlg(2) contains zero.
ifail=1
On entry, (ar,ai)=(0,0).
ifail=2
On entry, (ar,ai)=(0,0) and (br,bi)=(0,0).
ifail=3
On entry, (ar,ai)=(0,0) and the root -(cr,ci)/(br,bi) overflows: ar=value, cr=value, br=value, ai=value, ci=value and bi=value.
ifail=4
On entry, (cr,ci)=(0,0) and the root -(br,bi)/(ar,ai) overflows: cr=value, br=value, ar=value, ci=value, bi=value and ai=value.
ifail=5
On entry, B is so large that B2 is indistinguishable from (B2-4×A×C) and the root -(br,bi)/(ar,ai) overflows: B=max(|br|,|bi|)=value, A=max(|ar|,|ai|)=value, C=max(|cr|,|ci|)=value, br=value, bi=value, ar=value and ai=value.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

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

c02ahf is not threaded in any implementation.

9 Further Comments

None.

10 Example

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

10.1 Program Text

Program Text (c02ahfe.f90)

10.2 Program Data

Program Data (c02ahfe.d)

10.3 Program Results

Program Results (c02ahfe.r)