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_lapack_dhseqr (f08pe)

## Purpose

nag_lapack_dhseqr (f08pe) 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.

## Syntax

[h, wr, wi, z, info] = f08pe(job, compz, ilo, ihi, h, z, 'n', n)
[h, wr, wi, z, info] = nag_lapack_dhseqr(job, compz, ilo, ihi, h, z, 'n', n)

## Description

nag_lapack_dhseqr (f08pe) computes all the eigenvalues and, optionally, the Schur factorization of a real upper Hessenberg matrix H$H$:
 H = ZTZT , $H = ZTZT ,$
where T$T$ is an upper quasi-triangular matrix (the Schur form of H$H$), and Z$Z$ is the orthogonal matrix whose columns are the Schur vectors zi${z}_{i}$. See Section [Further Comments] for details of the structure of T$T$.
The function may also be used to compute the Schur factorization of a real general matrix A$A$ which has been reduced to upper Hessenberg form H$H$:
 A = QHQT, where ​Q​ is orthogonal, = (QZ)T(QZ)T.
$A = QHQT, where ​Q​ is orthogonal, = (QZ)T(QZ)T.$
In this case, after nag_lapack_dgehrd (f08ne) has been called to reduce A$A$ to Hessenberg form, nag_lapack_dorghr (f08nf) must be called to form Q$Q$ explicitly; Q$Q$ is then passed to nag_lapack_dhseqr (f08pe), which must be called with compz = 'V'${\mathbf{compz}}=\text{'V'}$.
The function can also take advantage of a previous call to nag_lapack_dgebal (f08nh) which may have balanced the original matrix before reducing it to Hessenberg form, so that the Hessenberg matrix H$H$ has the structure:
 H11 H12 H13 H22 H23 H33
$H11 H12 H13 H22 H23 H33$
where H11${H}_{11}$ and H33${H}_{33}$ are upper triangular. If so, only the central diagonal block H22${H}_{22}$ (in rows and columns ilo${i}_{\mathrm{lo}}$ to ihi${i}_{\mathrm{hi}}$) needs to be further reduced to Schur form (the blocks H12${H}_{12}$ and H23${H}_{23}$ are also affected). Therefore the values of ilo${i}_{\mathrm{lo}}$ and ihi${i}_{\mathrm{hi}}$ can be supplied to nag_lapack_dhseqr (f08pe) directly. Also, nag_lapack_dgebak (f08nj) must be called after this function to permute the Schur vectors of the balanced matrix to those of the original matrix. If nag_lapack_dgebal (f08nh) has not been called however, then ilo${i}_{\mathrm{lo}}$ must be set to 1$1$ and ihi${i}_{\mathrm{hi}}$ to n$n$. Note that if the Schur factorization of A$A$ is required, nag_lapack_dgebal (f08nh) must not be called with job = 'S'${\mathbf{job}}=\text{'S'}$ or 'B'$\text{'B'}$, because the balancing transformation is not orthogonal.
nag_lapack_dhseqr (f08pe) uses a multishift form of the upper Hessenberg QR$QR$ algorithm, due to Bai and Demmel (1989). The Schur vectors are normalized so that zi2 = 1${‖{z}_{i}‖}_{2}=1$, but are determined only to within a factor ± 1$±1$.

## References

Bai Z and Demmel J W (1989) On a block implementation of Hessenberg multishift QR$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

## Parameters

### Compulsory Input Parameters

1:     job – string (length ≥ 1)
Indicates whether eigenvalues only or the Schur form T$T$ is required.
job = 'E'${\mathbf{job}}=\text{'E'}$
Eigenvalues only are required.
job = 'S'${\mathbf{job}}=\text{'S'}$
The Schur form T$T$ is required.
Constraint: job = 'E'${\mathbf{job}}=\text{'E'}$ or 'S'$\text{'S'}$.
2:     compz – string (length ≥ 1)
Indicates whether the Schur vectors are to be computed.
compz = 'N'${\mathbf{compz}}=\text{'N'}$
No Schur vectors are computed (and the array z is not referenced).
compz = 'I'${\mathbf{compz}}=\text{'I'}$
The Schur vectors of H$H$ are computed (and the array z is initialized by the function).
compz = 'V'${\mathbf{compz}}=\text{'V'}$
The Schur vectors of A$A$ are computed (and the array z must contain the matrix Q$Q$ on entry).
Constraint: compz = 'N'${\mathbf{compz}}=\text{'N'}$, 'V'$\text{'V'}$ or 'I'$\text{'I'}$.
3:     ilo – int64int32nag_int scalar
4:     ihi – int64int32nag_int scalar
If the matrix A$A$ has been balanced by nag_lapack_dgebal (f08nh), then ilo and ihi must contain the values returned by that function. Otherwise, ilo must be set to 1$1$ and ihi to n.
Constraint: ilo1${\mathbf{ilo}}\ge 1$ and min (ilo,n) ihin $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ilo}},{\mathbf{n}}\right)\le {\mathbf{ihi}}\le {\mathbf{n}}$.
5:     h(ldh, : $:$) – double array
The first dimension of the array h must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The n$n$ by n$n$ upper Hessenberg matrix H$H$, as returned by nag_lapack_dgehrd (f08ne).
6:     z(ldz, : $:$) – double array
The first dimension, ldz, of the array z must satisfy
• if compz = 'I'${\mathbf{compz}}=\text{'I'}$ or 'V'$\text{'V'}$, ldz max (1,n) $\mathit{ldz}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if compz = 'N'${\mathbf{compz}}=\text{'N'}$, ldz1$\mathit{ldz}\ge 1$.
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if compz = 'V'${\mathbf{compz}}=\text{'V'}$ or 'I'$\text{'I'}$ and at least 1$1$ if compz = 'N'${\mathbf{compz}}=\text{'N'}$
If compz = 'V'${\mathbf{compz}}=\text{'V'}$, z must contain the orthogonal matrix Q$Q$ from the reduction to Hessenberg form.
If compz = 'I'${\mathbf{compz}}=\text{'I'}$, z need not be set.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the array h and the second dimension of the array h. (An error is raised if these dimensions are not equal.)
n$n$, the order of the matrix H$H$.
Constraint: n0${\mathbf{n}}\ge 0$.

### Input Parameters Omitted from the MATLAB Interface

ldh ldz work lwork

### Output Parameters

1:     h(ldh, : $:$) – double array
The first dimension of the array h will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
ldhmax (1,n)$\mathit{ldh}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
If job = 'E'${\mathbf{job}}=\text{'E'}$, the array contains no useful information.
If job = 'S'${\mathbf{job}}=\text{'S'}$, h stores the upper quasi-triangular matrix T$T$ from the Schur decomposition (the Schur form) unless ${\mathbf{INFO}}>{\mathbf{0}}$.
2:     wr( : $:$) – double array
3:     wi( : $:$) – double array
Note: the dimension of the arrays wr and wi must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The real and imaginary parts, respectively, of the computed eigenvalues, unless ${\mathbf{INFO}}>{\mathbf{0}}$ (in which case see Section [Error Indicators and Warnings]). 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$T$ (if computed); see Section [Further Comments] for details.
4:     z(ldz, : $:$) – double array
The first dimension, ldz, of the array z will be
• if compz = 'I'${\mathbf{compz}}=\text{'I'}$ or 'V'$\text{'V'}$, ldz max (1,n) $\mathit{ldz}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if compz = 'N'${\mathbf{compz}}=\text{'N'}$, ldz1$\mathit{ldz}\ge 1$.
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if compz = 'V'${\mathbf{compz}}=\text{'V'}$ or 'I'$\text{'I'}$ and at least 1$1$ if compz = 'N'${\mathbf{compz}}=\text{'N'}$
If compz = 'V'${\mathbf{compz}}=\text{'V'}$ or 'I'$\text{'I'}$, z contains the orthogonal matrix of the required Schur vectors, unless ${\mathbf{INFO}}>{\mathbf{0}}$.
If compz = 'N'${\mathbf{compz}}=\text{'N'}$, z is not referenced.
5:     info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: job, 2: compz, 3: n, 4: ilo, 5: ihi, 6: h, 7: ldh, 8: wr, 9: wi, 10: z, 11: ldz, 12: work, 13: lwork, 14: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
W INFO > 0${\mathbf{INFO}}>0$
The algorithm has failed to find all the eigenvalues after a total of 30 × (ihiilo + 1)$30×\left({\mathbf{ihi}}-{\mathbf{ilo}}+1\right)$ iterations. If info = i${\mathbf{info}}=i$, elements 1,2,,ilo1$1,2,\dots ,{\mathbf{ilo}}-1$ and i + 1,i + 2,,n$i+1,i+2,\dots ,n$ of wr and wi contain the real and imaginary parts of contain the eigenvalues which have been found.
If job = 'E'${\mathbf{job}}=\text{'E'}$, then on exit, the remaining unconverged eigenvalues are the eigenvalues of the upper Hessenberg matrix $\stackrel{^}{H}$, formed from h(,) ${\mathbf{h}}\left({\mathbf{ilo}}:{\mathbf{info}},{\mathbf{ilo}}:{\mathbf{info}}\right)$, i.e., the ilo through info rows and columns of the final output matrix H$H$.
If job = 'S'${\mathbf{job}}=\text{'S'}$, then on exit
 ( * )   Hi U = U H̃ $(*) Hi U = U H~$
for some matrix U$U$, where Hi${H}_{i}$ is the input upper Hessenberg matrix and $\stackrel{~}{H}$ is an upper Hessenberg matrix formed from h(info + 1 : ihi,info + 1 : ihi) ${\mathbf{h}}\left({\mathbf{info}}+1:{\mathbf{ihi}},{\mathbf{info}}+1:{\mathbf{ihi}}\right)$.
If compz = 'V'${\mathbf{compz}}=\text{'V'}$, then on exit
 Zout = Zin U $Zout = Zin U$
where U$U$ is defined in ( * )$\left(*\right)$ (regardless of the value of job).
If compz = 'I'${\mathbf{compz}}=\text{'I'}$, then on exit
 Zout = U $Zout = U$
where U$U$ is defined in ( * )$\left(*\right)$ (regardless of the value of job).
If ${\mathbf{INFO}}>{\mathbf{0}}$ and compz = 'N'${\mathbf{compz}}=\text{'N'}$, then z is not accessed.

## Accuracy

The computed Schur factorization is the exact factorization of a nearby matrix (H + E)$\left(H+E\right)$, where
 ‖E‖2 = O(ε) ‖H‖2 , $‖E‖2 = O(ε) ‖H‖2 ,$
and ε$\epsilon$ is the machine precision.
If λi${\lambda }_{i}$ is an exact eigenvalue, and λ̃i${\stackrel{~}{\lambda }}_{i}$ is the corresponding computed value, then
 |λ̃i − λi| ≤ ( c (n) ε ‖H‖2 )/(si) , $| λ~i - λi | ≤ c (n) ε ‖H‖2 si ,$
where c(n)$c\left(n\right)$ is a modestly increasing function of n$n$, and si${s}_{i}$ is the reciprocal condition number of λi${\lambda }_{i}$. The condition numbers si${s}_{i}$ may be computed by calling nag_lapack_dtrsna (f08ql).

## Further Comments

The total number of floating point operations depends on how rapidly the algorithm converges, but is typically about:
• 7n3$7{n}^{3}$ if only eigenvalues are computed;
• 10n3$10{n}^{3}$ if the Schur form is computed;
• 20n3$20{n}^{3}$ if the full Schur factorization is computed.
The Schur form T$T$ has the following structure (referred to as canonical Schur form).
If all the computed eigenvalues are real, T$T$ is upper triangular, and the diagonal elements of T$T$ are the eigenvalues; wr(i) = tii${\mathbf{wr}}\left(\mathit{i}\right)={t}_{\mathit{i}\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$, and wi(i) = 0.0${\mathbf{wi}}\left(i\right)=0.0$.
If some of the computed eigenvalues form complex conjugate pairs, then T$T$ has 2$2$ by 2$2$ diagonal blocks. Each diagonal block has the form
 ( tii ti,i + 1 ) ti + 1,i ti + 1,i + 1
=
 ( α β ) γ α
$tii ti,i+1 ti+1,i ti+1,i+1 = α β γ α$
where βγ < 0$\beta \gamma <0$. The corresponding eigenvalues are α ± sqrt(βγ)$\alpha ±\sqrt{\beta \gamma }$; wr(i) = wr(i + 1) = α${\mathbf{wr}}\left(i\right)={\mathbf{wr}}\left(i+1\right)=\alpha$; wi(i) = + sqrt(|βγ|)${\mathbf{wi}}\left(i\right)=+\sqrt{|\beta \gamma |}$; wi(i + 1) = wi(i)${\mathbf{wi}}\left(i+1\right)=-{\mathbf{wi}}\left(i\right)$.
The complex analogue of this function is nag_lapack_zhseqr (f08ps).

## Example

```function nag_lapack_dhseqr_example
job = 'Schur form';
compz = 'Initialize Z';
ilo = int64(1);
ihi = int64(4);
h = [0.35, -0.116, -0.3886, -0.2942;
-0.514, 0.1225, 0.1004, 0.1126;
0, 0.6443, -0.1357, -0.0977;
0, 0, 0.4262, 0.1632];
z = zeros(4, 4);
[hOut, wr, wi, zOut, info] = nag_lapack_dhseqr(job, compz, ilo, ihi, h, z)
```
```

hOut =

0.7995    0.0061   -0.1144   -0.0335
0   -0.0994   -0.6483   -0.2026
0    0.2477   -0.0994   -0.3474
0         0         0   -0.1007

wr =

0.7995
-0.0994
-0.0994
-0.1007

wi =

0
0.4008
-0.4008
0

zOut =

-0.6551   -0.3450   -0.1036    0.6641
0.5972   -0.1706    0.5246    0.5823
0.3845   -0.7143   -0.5789   -0.0821
0.2576    0.5845   -0.6156    0.4616

info =

0

```
```function f08pe_example
job = 'Schur form';
compz = 'Initialize Z';
ilo = int64(1);
ihi = int64(4);
h = [0.35, -0.116, -0.3886, -0.2942;
-0.514, 0.1225, 0.1004, 0.1126;
0, 0.6443, -0.1357, -0.0977;
0, 0, 0.4262, 0.1632];
z = zeros(4, 4);
[hOut, wr, wi, zOut, info] = f08pe(job, compz, ilo, ihi, h, z)
```
```

hOut =

0.7995    0.0061   -0.1144   -0.0335
0   -0.0994   -0.6483   -0.2026
0    0.2477   -0.0994   -0.3474
0         0         0   -0.1007

wr =

0.7995
-0.0994
-0.0994
-0.1007

wi =

0
0.4008
-0.4008
0

zOut =

-0.6551   -0.3450   -0.1036    0.6641
0.5972   -0.1706    0.5246    0.5823
0.3845   -0.7143   -0.5789   -0.0821
0.2576    0.5845   -0.6156    0.4616

info =

0

```

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