# NAG Library Routine Document

## 1Purpose

f08jvf (zstedc) computes all the eigenvalues and, optionally, all the eigenvectors of a real $n$ by $n$ symmetric tridiagonal matrix, or of a complex full or banded Hermitian matrix which has been reduced to tridiagonal form.

## 2Specification

Fortran Interface
 Subroutine f08jvf ( n, d, e, z, ldz, work, info)
 Integer, Intent (In) :: n, ldz, lwork, lrwork, liwork Integer, Intent (Out) :: iwork(max(1,liwork)), info Real (Kind=nag_wp), Intent (Inout) :: d(*), e(*) Real (Kind=nag_wp), Intent (Out) :: rwork(max(1,lrwork)) Complex (Kind=nag_wp), Intent (Inout) :: z(ldz,*) Complex (Kind=nag_wp), Intent (Out) :: work(max(1,lwork)) Character (1), Intent (In) :: compz
#include nagmk26.h
 void f08jvf_ (const char *compz, const Integer *n, double d[], double e[], Complex z[], const Integer *ldz, Complex work[], const Integer *lwork, double rwork[], const Integer *lrwork, Integer iwork[], const Integer *liwork, Integer *info, const Charlen length_compz)
The routine may be called by its LAPACK name zstedc.

## 3Description

f08jvf (zstedc) computes all the eigenvalues and, optionally, the eigenvectors of a real symmetric tridiagonal matrix $T$. That is, the routine computes the spectral factorization of $T$ given by
 $T = Z Λ ZT ,$
where $\Lambda$ is a diagonal matrix whose diagonal elements are the eigenvalues, ${\lambda }_{i}$, of $T$ and $Z$ is an orthogonal matrix whose columns are the eigenvectors, ${z}_{i}$, of $T$. Thus
 $Tzi = λi zi , i = 1,2,…,n .$
The routine may also be used to compute all the eigenvalues and eigenvectors of a complex full, or banded, Hermitian matrix $A$ which has been reduced to real tridiagonal form $T$ as
 $A = QTQH ,$
where $Q$ is unitary. The spectral factorization of $A$ is then given by
 $A = QZ Λ QZH .$
In this case $Q$ must be formed explicitly and passed to f08jvf (zstedc) in the array z, and the routine called with ${\mathbf{compz}}=\text{'V'}$. Routines which may be called to form $T$ and $Q$ are
 full matrix f08fsf (zhetrd) and f08ftf (zungtr) full matrix, packed storage f08gsf (zhptrd) and f08gtf (zupgtr) band matrix f08hsf (zhbtrd), with ${\mathbf{vect}}=\text{'V'}$
When only eigenvalues are required then this routine calls f08jff (dsterf) to compute the eigenvalues of the tridiagonal matrix $T$, but when eigenvectors of $T$ are also required and the matrix is not too small, then a divide and conquer method is used, which can be much faster than f08jsf (zsteqr), although more storage is required.

## 4References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1:     $\mathbf{compz}$ – Character(1)Input
On entry: indicates whether the eigenvectors are to be computed.
${\mathbf{compz}}=\text{'N'}$
Only the eigenvalues are computed (and the array z is not referenced).
${\mathbf{compz}}=\text{'V'}$
The eigenvalues and eigenvectors of $A$ are computed (and the array z must contain the matrix $Q$ on entry).
${\mathbf{compz}}=\text{'I'}$
The eigenvalues and eigenvectors of $T$ are computed (and the array z is initialized by the routine).
Constraint: ${\mathbf{compz}}=\text{'N'}$, $\text{'V'}$ or $\text{'I'}$.
2:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the symmetric tridiagonal matrix $T$.
Constraint: ${\mathbf{n}}\ge 0$.
3:     $\mathbf{d}\left(*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the dimension of the array d must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the diagonal elements of the tridiagonal matrix.
On exit: if ${\mathbf{info}}={\mathbf{0}}$, the eigenvalues in ascending order.
4:     $\mathbf{e}\left(*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the dimension of the array e must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}-1\right)$.
On entry: the subdiagonal elements of the tridiagonal matrix.
On exit: e is overwritten.
5:     $\mathbf{z}\left({\mathbf{ldz}},*\right)$ – Complex (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array z must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{compz}}=\text{'V'}$ or $\text{'I'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{compz}}=\text{'V'}$, z must contain the unitary matrix $Q$ used in the reduction to tridiagonal form.
On exit: if ${\mathbf{compz}}=\text{'V'}$, z contains the orthonormal eigenvectors of the original Hermitian matrix $A$, and if ${\mathbf{compz}}=\text{'I'}$, z contains the orthonormal eigenvectors of the symmetric tridiagonal matrix $T$.
If ${\mathbf{compz}}=\text{'N'}$, z is not referenced.
6:     $\mathbf{ldz}$ – IntegerInput
On entry: the first dimension of the array z as declared in the (sub)program from which f08jvf (zstedc) is called.
Constraints:
• if ${\mathbf{compz}}=\text{'V'}$ or $\text{'I'}$, ${\mathbf{ldz}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{ldz}}\ge 1$.
7:     $\mathbf{work}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lwork}}\right)\right)$ – Complex (Kind=nag_wp) arrayWorkspace
On exit: if ${\mathbf{info}}={\mathbf{0}}$, the real part of ${\mathbf{work}}\left(1\right)$ contains the minimum value of lwork required for optimal performance.
8:     $\mathbf{lwork}$ – IntegerInput
On entry: the dimension of the array work as declared in the (sub)program from which f08jvf (zstedc) is called.
If ${\mathbf{lwork}}=-1$, a workspace query is assumed; the routine only calculates the optimal sizes of the work, rwork and iwork arrays, returns these values as the first entries of the work, rwork and iwork arrays, and no error message related to lwork, lrwork or liwork is issued.
Constraints:
if ${\mathbf{lwork}}\ne -1$,
• if ${\mathbf{compz}}=\text{'N'}$ or $\text{'I'}$ or ${\mathbf{n}}\le 1$, ${\mathbf{lwork}}\ge 1$;
• if ${\mathbf{compz}}=\text{'V'}$ and ${\mathbf{n}}>1$, ${\mathbf{lwork}}\ge {{\mathbf{n}}}^{2}$.
Note: that for ${\mathbf{compz}}=\text{'V'}$, then if n is less than or equal to the minimum divide size, usually $25$, lwork need only be $1$.
9:     $\mathbf{rwork}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lrwork}}\right)\right)$ – Real (Kind=nag_wp) arrayWorkspace
On exit: if ${\mathbf{info}}={\mathbf{0}}$, ${\mathbf{rwork}}\left(1\right)$ returns the optimal lrwork.
10:   $\mathbf{lrwork}$ – IntegerInput
On entry: the dimension of the array rwork as declared in the (sub)program from which f08jvf (zstedc) is called.
If ${\mathbf{lrwork}}=-1$, a workspace query is assumed; the routine only calculates the optimal sizes of the work, rwork and iwork arrays, returns these values as the first entries of the work, rwork and iwork arrays, and no error message related to lwork, lrwork or liwork is issued.
Constraints:
if ${\mathbf{lrwork}}\ne -1$,
• if ${\mathbf{compz}}=\text{'N'}$ or ${\mathbf{n}}\le 1$, ${\mathbf{lrwork}}\ge 1$;
• if ${\mathbf{compz}}=\text{'V'}$ and ${\mathbf{n}}>1$, ${\mathbf{lrwork}}\ge 1+3×{\mathbf{n}}+2×{\mathbf{n}}×\mathit{lg}\left({\mathbf{n}}\right)+4×{{\mathbf{n}}}^{2}$, where $\mathit{lg}\left({\mathbf{n}}\right)=\text{}$smallest integer $k$ such that ${2}^{k}\ge {\mathbf{n}}$;
• if ${\mathbf{compz}}=\text{'I'}$ and ${\mathbf{n}}>1$, ${\mathbf{lrwork}}\ge 1+4×{\mathbf{n}}+2×{{\mathbf{n}}}^{2}$.
Note: that for ${\mathbf{compz}}=\text{'V'}$ or $\text{'I'}$ if n is less than or equal to the minimum divide size, usually $25$, then lrwork need only be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2×\left({\mathbf{n}}-1\right)\right)$.
11:   $\mathbf{iwork}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{liwork}}\right)\right)$ – Integer arrayWorkspace
On exit: if ${\mathbf{info}}={\mathbf{0}}$, ${\mathbf{iwork}}\left(1\right)$ returns the optimal liwork.
12:   $\mathbf{liwork}$ – IntegerInput
On entry: the dimension of the array iwork as declared in the (sub)program from which f08jvf (zstedc) is called.
If ${\mathbf{liwork}}=-1$, a workspace query is assumed; the routine only calculates the optimal sizes of the work, rwork and iwork arrays, returns these values as the first entries of the work, rwork and iwork arrays, and no error message related to lwork, lrwork or liwork is issued.
Constraints:
if ${\mathbf{liwork}}\ne -1$,
• if ${\mathbf{compz}}=\text{'N'}$ or ${\mathbf{n}}\le 1$, ${\mathbf{liwork}}\ge 1$;
• if ${\mathbf{compz}}=\text{'V'}$ and ${\mathbf{n}}>1$, ${\mathbf{liwork}}\ge 6+6×{\mathbf{n}}+5×{\mathbf{n}}×\mathit{lg}\left({\mathbf{n}}\right)$;
• if ${\mathbf{compz}}=\text{'I'}$ and ${\mathbf{n}}>1$, ${\mathbf{liwork}}\ge 3+5×{\mathbf{n}}$.
13:   $\mathbf{info}$ – IntegerOutput
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error Indicators and Warnings

${\mathbf{info}}<0$
If ${\mathbf{info}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.
${\mathbf{info}}>0$
The algorithm failed to compute an eigenvalue while working on the submatrix lying in rows and columns $〈\mathit{\text{value}}〉/\left({\mathbf{n}}+1\right)$ through .

## 7Accuracy

The computed eigenvalues and eigenvectors are exact for a nearby matrix $\left(T+E\right)$, where
 $E2 = Oε T2 ,$
and $\epsilon$ is the machine precision.
If ${\lambda }_{i}$ is an exact eigenvalue and ${\stackrel{~}{\lambda }}_{i}$ is the corresponding computed value, then
 $λ~i - λi ≤ c n ε T2 ,$
where $c\left(n\right)$ is a modestly increasing function of $n$.
If ${z}_{i}$ is the corresponding exact eigenvector, and ${\stackrel{~}{z}}_{i}$ is the corresponding computed eigenvector, then the angle $\theta \left({\stackrel{~}{z}}_{i},{z}_{i}\right)$ between them is bounded as follows:
 $θ z~i,zi ≤ cnεT2 mini≠jλi-λj .$
Thus the accuracy of a computed eigenvector depends on the gap between its eigenvalue and all the other eigenvalues.
See Section 4.7 of Anderson et al. (1999) for further details. See also f08flf (ddisna).

## 8Parallelism and Performance

f08jvf (zstedc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f08jvf (zstedc) 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.

If only eigenvalues are required, the total number of floating-point operations is approximately proportional to ${n}^{2}$. When eigenvectors are required the number of operations is bounded above by approximately the same number of operations as f08jsf (zsteqr), but for large matrices f08jvf (zstedc) is usually much faster.
The real analogue of this routine is f08jhf (dstedc).

## 10Example

This example finds all the eigenvalues and eigenvectors of the Hermitian band matrix
 $A = -3.13i+0.00 1.94-2.10i -3.40+0.25i 0.00i+0.00 1.94+2.10i -1.91i+0.00 -0.82-0.89i -0.67+0.34i -3.40-0.25i -0.82+0.89i -2.87i+0.00 -2.10-0.16i 0.00i+0.00 -0.67-0.34i -2.10+0.16i 0.50i+0.00 .$
$A$ is first reduced to tridiagonal form by a call to f08hsf (zhbtrd).

### 10.1Program Text

Program Text (f08jvfe.f90)

### 10.2Program Data

Program Data (f08jvfe.d)

### 10.3Program Results

Program Results (f08jvfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017