NAG C Library Function Document

nag_dhseqr (f08pec)


nag_dhseqr (f08pec) computes all the eigenvalues and, optionally, the Schur factorization of a real Hessenberg matrix or a real general matrix which has been reduced to Hessenberg form.


#include <nag.h>
#include <nagf08.h>
void  nag_dhseqr (Nag_OrderType order, Nag_JobType job, Nag_ComputeZType compz, Integer n, Integer ilo, Integer ihi, double h[], Integer pdh, double wr[], double wi[], double z[], Integer pdz, NagError *fail)


nag_dhseqr (f08pec) computes all the eigenvalues and, optionally, the Schur factorization of a real upper Hessenberg matrix H:
H = ZTZT ,  
where T is an upper quasi-triangular matrix (the Schur form of H), and Z is the orthogonal matrix whose columns are the Schur vectors zi. See Section 9 for details of the structure of T.
The function may also be used to compute the Schur factorization of a real general matrix A which has been reduced to upper Hessenberg form H:
A = QHQT, where ​Q​ is orthogonal, = QZTQZT.  
In this case, after nag_dgehrd (f08nec) has been called to reduce A to Hessenberg form, nag_dorghr (f08nfc) must be called to form Q explicitly; Q is then passed to nag_dhseqr (f08pec), which must be called with compz=Nag_UpdateZ.
The function can also take advantage of a previous call to nag_dgebal (f08nhc) which may have balanced the original matrix before reducing it to Hessenberg form, so that the Hessenberg matrix H has the structure:
H11 H12 H13 H22 H23 H33  
where H11 and H33 are upper triangular. If so, only the central diagonal block H22 (in rows and columns ilo to ihi) needs to be further reduced to Schur form (the blocks H12 and H23 are also affected). Therefore the values of ilo and ihi can be supplied to nag_dhseqr (f08pec) directly. Also, nag_dgebak (f08njc) must be called after this function to permute the Schur vectors of the balanced matrix to those of the original matrix. If nag_dgebal (f08nhc) has not been called however, then ilo must be set to 1 and ihi to n. Note that if the Schur factorization of A is required, nag_dgebal (f08nhc) must not be called with job=Nag_Scale or Nag_DoBoth, because the balancing transformation is not orthogonal.
nag_dhseqr (f08pec) uses a multishift form of the upper Hessenberg QR algorithm, due to Bai and Demmel (1989). The Schur vectors are normalized so that zi2=1, but are determined only to within a factor ±1.


Bai Z and Demmel J W (1989) On a block implementation of Hessenberg multishift QR iteration Internat. J. High Speed Comput. 1 97–112
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore


1:     order Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     job Nag_JobTypeInput
On entry: indicates whether eigenvalues only or the Schur form T is required.
Eigenvalues only are required.
The Schur form T is required.
Constraint: job=Nag_EigVals or Nag_Schur.
3:     compz Nag_ComputeZTypeInput
On entry: indicates whether the Schur vectors are to be computed.
No Schur vectors are computed (and the array z is not referenced).
The Schur vectors of A are computed (and the array z must contain the matrix Q on entry).
The Schur vectors of H are computed (and the array z is initialized by the function).
Constraint: compz=Nag_NotZ, Nag_UpdateZ or Nag_InitZ.
4:     n IntegerInput
On entry: n, the order of the matrix H.
Constraint: n0.
5:     ilo IntegerInput
6:     ihi IntegerInput
On entry: if the matrix A has been balanced by nag_dgebal (f08nhc), ilo and ihi must contain the values returned by that function. Otherwise, ilo must be set to 1 and ihi to n.
Constraint: ilo1 and minilo,n ihin .
7:     h[dim] doubleInput/Output
Note: the dimension, dim, of the array h must be at least max1,pdh×n.
Where Hi,j appears in this document, it refers to the array element
  • h[j-1×pdh+i-1] when order=Nag_ColMajor;
  • h[i-1×pdh+j-1] when order=Nag_RowMajor.
On entry: the n by n upper Hessenberg matrix H, as returned by nag_dgehrd (f08nec).
On exit: if job=Nag_EigVals, the array contains no useful information.
If job=Nag_Schur, h is overwritten by the upper quasi-triangular matrix T from the Schur decomposition (the Schur form) unless fail.code= NE_CONVERGENCE.
8:     pdh IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array h.
Constraint: pdhmax1,n.
9:     wr[dim] doubleOutput
10:   wi[dim] doubleOutput
Note: the dimension, dim, of the arrays wr and wi must be at least max1,n.
On exit: the real and imaginary parts, respectively, of the computed eigenvalues, unless fail.code= NE_CONVERGENCE (in which case see Section 6). Complex conjugate pairs of eigenvalues appear consecutively with the eigenvalue having positive imaginary part first. The eigenvalues are stored in the same order as on the diagonal of the Schur form T (if computed); see Section 9 for details.
11:   z[dim] doubleInput/Output
Note: the dimension, dim, of the array z must be at least
  • max1,pdz×n when compz=Nag_UpdateZ or Nag_InitZ;
  • 1 when compz=Nag_NotZ.
The i,jth element of the matrix Z is stored in
  • z[j-1×pdz+i-1] when order=Nag_ColMajor;
  • z[i-1×pdz+j-1] when order=Nag_RowMajor.
On entry: if compz=Nag_UpdateZ, z must contain the orthogonal matrix Q from the reduction to Hessenberg form.
If compz=Nag_InitZ, z need not be set.
On exit: if compz=Nag_UpdateZ or Nag_InitZ, z contains the orthogonal matrix of the required Schur vectors, unless fail.code= NE_CONVERGENCE.
If compz=Nag_NotZ, z is not referenced.
12:   pdz IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array z.
  • if compz=Nag_UpdateZ or Nag_InitZ, pdz max1,n ;
  • if compz=Nag_NotZ, pdz1.
13:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
The algorithm has failed to find all the eigenvalues after a total of 30ihi-ilo+1 iterations.
If fail.errnum=i, elements 1,2,,ilo-1 and i+1,i+2,,n of wr and wi contain the real and imaginary parts of contain the eigenvalues which have been found.
If job=Nag_EigVals, then on exit, the remaining unconverged eigenvalues are the eigenvalues of the upper Hessenberg matrix H^, formed from Hilo:fail.errnum,ilo:fail.errnum , i.e., the ilo through fail.errnum rows and columns of the final output matrix H.
If job=Nag_Schur, then on exit
* Hi U = U H~  
for some matrix U, where Hi is the input upper Hessenberg matrix and H~ is an upper Hessenberg matrix formed from Hfail.errnum+1:ihi,fail.errnum+1:ihi .
If compz=Nag_UpdateZ, then on exit
Zout = Zin U  
where U is defined in * (regardless of the value of job).
If compz=Nag_InitZ, then on exit
Zout = U  
where U is defined in * (regardless of the value of job).
If fail.code= NE_CONVERGENCE and compz=Nag_NotZ, z is not accessed.
On entry, compz=value, pdz=value and n=value.
Constraint: if compz=Nag_UpdateZ or Nag_InitZ, pdz max1,n ;
if compz=Nag_NotZ, pdz1.
On entry, n=value.
Constraint: n0.
On entry, pdh=value.
Constraint: pdh>0.
On entry, pdz=value.
Constraint: pdz>0.
On entry, pdh=value and n=value.
Constraint: pdhmax1,n.
On entry, n=value, ilo=value and ihi=value.
Constraint: ilo1 and minilo,n ihin .
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.


The computed Schur factorization is the exact factorization of a nearby matrix H+E, where
E2 = Oε H2 ,  
and ε is the machine precision.
If λi is an exact eigenvalue, and λ~i is the corresponding computed value, then
λ~i - λi c n ε H2 si ,  
where cn is a modestly increasing function of n, and si is the reciprocal condition number of λi. The condition numbers si may be computed by calling nag_dtrsna (f08qlc).

Parallelism and Performance

nag_dhseqr (f08pec) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_dhseqr (f08pec) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Further Comments

The total number of floating-point operations depends on how rapidly the algorithm converges, but is typically about:
The Schur form T has the following structure (referred to as canonical Schur form).
If all the computed eigenvalues are real, T is upper triangular, and the diagonal elements of T are the eigenvalues; wr[i-1]=tii, for i=1,2,,n, and wi[i-1]=0.0.
If some of the computed eigenvalues form complex conjugate pairs, then T has 2 by 2 diagonal blocks. Each diagonal block has the form
tii ti,i+1 ti+1,i ti+1,i+1 = α β γ α  
where βγ<0. The corresponding eigenvalues are α±βγ; wr[i-1]=wr[i]=α; wi[i-1]=+βγ; wi[i]=-wi[i-1].
The complex analogue of this function is nag_zhseqr (f08psc).


This example computes all the eigenvalues and the Schur factorization of the upper Hessenberg matrix H, where
H = 0.3500 -0.1160 -0.3886 -0.2942 -0.5140 0.1225 0.1004 0.1126 0.0000 0.6443 -0.1357 -0.0977 0.0000 0.0000 0.4262 0.1632 .  
See also Section 10 in nag_dorghr (f08nfc), which illustrates the use of this function to compute the Schur factorization of a general matrix.

Program Text

Program Text (f08pece.c)

Program Data

Program Data (f08pece.d)

Program Results

Program Results (f08pece.r)