Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_dopgtr (f08gf)

## Purpose

nag_lapack_dopgtr (f08gf) generates the real orthogonal matrix $Q$, which was determined by nag_lapack_dsptrd (f08ge) when reducing a symmetric matrix to tridiagonal form.

## Syntax

[q, info] = f08gf(uplo, n, ap, tau)
[q, info] = nag_lapack_dopgtr(uplo, n, ap, tau)

## Description

nag_lapack_dopgtr (f08gf) is intended to be used after a call to nag_lapack_dsptrd (f08ge), which reduces a real symmetric matrix $A$ to symmetric tridiagonal form $T$ by an orthogonal similarity transformation: $A=QT{Q}^{\mathrm{T}}$. nag_lapack_dsptrd (f08ge) represents the orthogonal matrix $Q$ as a product of $n-1$ elementary reflectors.
This function may be used to generate $Q$ explicitly as a square matrix.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{uplo}$ – string (length ≥ 1)
This must be the same argument uplo as supplied to nag_lapack_dsptrd (f08ge).
Constraint: ${\mathbf{uplo}}=\text{'U'}$ or $\text{'L'}$.
2:     $\mathrm{n}$int64int32nag_int scalar
$n$, the order of the matrix $Q$.
Constraint: ${\mathbf{n}}\ge 0$.
3:     $\mathrm{ap}\left(:\right)$ – double array
The dimension of the array ap must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$
Details of the vectors which define the elementary reflectors, as returned by nag_lapack_dsptrd (f08ge).
4:     $\mathrm{tau}\left(:\right)$ – double array
The dimension of the array tau must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}-1\right)$
Further details of the elementary reflectors, as returned by nag_lapack_dsptrd (f08ge).

None.

### Output Parameters

1:     $\mathrm{q}\left(\mathit{ldq},:\right)$ – double array
The first dimension of the array q will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The second dimension of the array q will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The $n$ by $n$ orthogonal matrix $Q$.
2:     $\mathrm{info}$int64int32nag_int scalar
${\mathbf{info}}=0$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

${\mathbf{info}}=-i$
If ${\mathbf{info}}=-i$, parameter $i$ had an illegal value on entry. The parameters are numbered as follows:
1: uplo, 2: n, 3: ap, 4: tau, 5: q, 6: ldq, 7: work, 8: 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.

## Accuracy

The computed matrix $Q$ differs from an exactly orthogonal matrix by a matrix $E$ such that
 $E2 = Oε ,$
where $\epsilon$ is the machine precision.

The total number of floating-point operations is approximately $\frac{4}{3}{n}^{3}$.
The complex analogue of this function is nag_lapack_zupgtr (f08gt).

## Example

This example computes all the eigenvalues and eigenvectors of the matrix $A$, where
 $A = 2.07 3.87 4.20 -1.15 3.87 -0.21 1.87 0.63 4.20 1.87 1.15 2.06 -1.15 0.63 2.06 -1.81 ,$
using packed storage. Here $A$ is symmetric and must first be reduced to tridiagonal form by nag_lapack_dsptrd (f08ge). The program then calls nag_lapack_dopgtr (f08gf) to form $Q$, and passes this matrix to nag_lapack_dsteqr (f08je) which computes the eigenvalues and eigenvectors of $A$.
```function f08gf_example

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

% Symmetric matrix A stored in symmetric packed format (Lower)
uplo = 'L';
n = int64(4);
ap = [2.07;     3.87;     4.2;     -1.15;
-0.21;     1.87;     0.63;
1.15;     2.06;
-1.81];
% Reduce A to tridiagonal form
[apf, d, e, tau, info] = f08ge( ...
uplo, n, ap);

% Form Q
[q, info] = f08gf( ...
uplo, n, apf, tau);

% Calculate eigenvalues and eigenvectors
compz = 'Vectors';
[w, ~, z, info] = f08je( ...
compz, d, e, 'z', q);

disp('Eigenvalues');
disp(w');

% Normalize eigenvectors: largest element positive
for j = 1:n
[~,k] = max(abs(z(:,j)));
if z(k,j) < 0;
z(:,j) = -z(:,j);
end
end

disp('Eigenvectors');
disp(z);

```
```f08gf example results

Eigenvalues
-5.0034   -1.9987    0.2013    8.0008

Eigenvectors
0.5658   -0.2328   -0.3965    0.6845
-0.3478    0.7994   -0.1780    0.4564
-0.4740   -0.4087    0.5381    0.5645
0.5781    0.3737    0.7221    0.0676

```