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_cubic_real (c02ak)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_zeros_cubic_real (c02ak) determines the roots of a cubic equation with real coefficients.


[zeror, zeroi, errest, ifail] = c02ak(u, r, s, t)
[zeror, zeroi, errest, ifail] = nag_zeros_cubic_real(u, r, s, t)


nag_zeros_cubic_real (c02ak) attempts to find the roots of the cubic equation
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 nag_lapack_dhseqr (f08pe). Further details can be found in Further Comments.
To obtain the roots of a quartic equation, nag_zeros_quartic_real (c02al) can be used.


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


Compulsory Input Parameters

1:     u – double scalar
u, the coefficient of z3.
Constraint: u0.0.
2:     r – double scalar
r, the coefficient of z2.
3:     s – double scalar
s, the coefficient of z.
4:     t – double scalar
t, the constant coefficient.

Optional Input Parameters


Output Parameters

1:     zeror3 – double array
2:     zeroi3 – double array
zerori and zeroii contain the real and imaginary parts, respectively, of the ith root.
3:     errest3 – double array
erresti contains an approximate error estimate for the ith root.
4:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,u=0.0.
The companion matrix H cannot be formed without overflow.
The iterative procedure used to determine the eigenvalues has failed to converge.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


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

Further Comments

The method used by the function consists of the following steps, which are performed by functions 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).


This example finds the roots of the cubic equation
function c02ak_example

fprintf('c02ak example results\n\n');

% roots of cubic z^3 + 3*z^2 + 9*z - 13 = 0
u =   1;
r =   3;
s =   9;
t = -13;
[zr, zi, errest, ifail] = c02ak(u, r, s, t);

fprintf('  Roots of cubic      error estimates\n');
for j = 1:3
   if (zi(j)<0)
     fprintf('%8.4f - %7.4fi     %8.2e\n',zr(j),abs(zi(j)),errest(j));
     fprintf('%8.4f - %7.4fi     %8.2e\n',zr(j),abs(zi(j)),errest(j));

c02ak example results

  Roots of cubic      error estimates
  1.0000 -  0.0000i     1.00e-15
 -2.0000 -  3.0000i     1.04e-15
 -2.0000 -  3.0000i     1.04e-15

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–2015