NAG Library Routine Document

c02akf (cubic_real)

1
Purpose

c02akf determines the roots of a cubic equation with real coefficients.

2
Specification

Fortran Interface
Subroutine c02akf ( u, r, s, t, zeror, zeroi, errest, ifail)
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: u, r, s, t
Real (Kind=nag_wp), Intent (Out):: zeror(3), zeroi(3), errest(3)
C Header Interface
#include <nagmk26.h>
void  c02akf_ (const double *u, const double *r, const double *s, const double *t, double zeror[], double zeroi[], double errest[], Integer *ifail)

3
Description

c02akf attempts to find the roots of the cubic equation
uz3+rz2+sz+t=0,  
where u, r, s and t are real coefficients with u0. The roots are located by finding the eigenvalues of the associated 3 by 3 (upper Hessenberg) companion matrix H given by
H= 0 0 -t/u 1 0 -s/u 0 1 -r/u .  
The eigenvalues are obtained by a call to f08pef (dhseqr). Further details can be found in Section 9.
To obtain the roots of a quartic equation, c02alf can be used.

4
References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

5
Arguments

1:     u – Real (Kind=nag_wp)Input
On entry: u, the coefficient of z3.
Constraint: u0.0.
2:     r – Real (Kind=nag_wp)Input
On entry: r, the coefficient of z2.
3:     s – Real (Kind=nag_wp)Input
On entry: s, the coefficient of z.
4:     t – Real (Kind=nag_wp)Input
On entry: t, the constant coefficient.
5:     zeror3 – Real (Kind=nag_wp) arrayOutput
6:     zeroi3 – Real (Kind=nag_wp) arrayOutput
On exit: zerori and zeroii contain the real and imaginary parts, respectively, of the ith root.
7:     errest3 – Real (Kind=nag_wp) arrayOutput
On exit: erresti contains an approximate error estimate for the ith root.
8:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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, u=0.0.
Constraint: u0.0.
ifail=2
The companion matrix H cannot be formed without overflow.
ifail=3
Failure to converge in f08pef (dhseqr).
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

If ifail=0 on exit, then the ith computed root should have approximately log10erresti  correct significant digits.

8
Parallelism and Performance

c02akf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
c02akf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9
Further Comments

The method used by the routine consists of the following steps, which are performed by routines from LAPACK in Chapter F08.
(a) Form matrix H.
(b) Apply a diagonal similarity transformation to H (to give H).
(c) Calculate the eigenvalues and Schur factorization of H.
(d) Calculate the left and right eigenvectors of H.
(e) Estimate reciprocal condition numbers for all the eigenvalues of H.
(f) Calculate approximate error estimates for all the eigenvalues of H (using the 1-norm).

10
Example

This example finds the roots of the cubic equation
z3+3z2+9z-13=0.  

10.1
Program Text

Program Text (c02akfe.f90)

10.2
Program Data

Program Data (c02akfe.d)

10.3
Program Results

Program Results (c02akfe.r)