F05 Chapter Contents
F05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF05AAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F05AAF applies the Schmidt orthogonalization process to $n$ vectors in $m$-dimensional space, $n\le m$.

## 2  Specification

 SUBROUTINE F05AAF ( A, LDA, M, N1, N2, S, CC, ICOL, IFAIL)
 INTEGER LDA, M, N1, N2, ICOL, IFAIL REAL (KIND=nag_wp) A(LDA,N2), S(N2), CC

## 3  Description

F05AAF applies the Schmidt orthogonalization process to $n$ linearly independent vectors in $m$-dimensional space, $n\le m$. The effect of this process is to replace the original $n$ vectors by $n$ orthonormal vectors which have the property that the $\mathit{r}$th vector is linearly dependent on the first $\mathit{r}$ of the original vectors, and that the sum of squares of the elements of the $\mathit{r}$th vector is equal to $1$, for $\mathit{r}=1,2,\dots ,n$. Inner-products are accumulated using additional precision.
None.

## 5  Parameters

1:     A(LDA,N2) – REAL (KIND=nag_wp) arrayInput/Output
On entry: columns N1 to N2 contain the vectors to be orthogonalized. The vectors are stored by columns in elements $1$ to $m$.
On exit: these vectors are overwritten by the orthonormal vectors.
2:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F05AAF is called.
Constraint: ${\mathbf{LDA}}\ge {\mathbf{M}}$.
3:     M – INTEGERInput
On entry: $m$, the number of elements in each vector.
4:     N1 – INTEGERInput
5:     N2 – INTEGERInput
On entry: the indices of the first and last columns of $A$ to be orthogonalized.
Constraint: ${\mathbf{N1}}\le {\mathbf{N2}}$.
6:     S(N2) – REAL (KIND=nag_wp) arrayWorkspace
7:     CC – REAL (KIND=nag_wp)Output
On exit: is used to indicate linear dependence of the original vectors. The nearer CC is to $1.0$, the more likely vector ICOL is dependent on vectors N1 to ${\mathbf{ICOL}}-1$. See Section 8.
8:     ICOL – INTEGEROutput
On exit: the column number corresponding to CC. See Section 8.
9:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N1}}>{\mathbf{N2}}$.

## 7  Accuracy

Innerproducts are accumulated using additional precision arithmetic and full machine accuracy should be obtained except when ${\mathbf{CC}}>0.99999$. (See Section 8.)

The time taken by F05AAF is approximately proportional to $n{m}^{2}$, where $n={\mathbf{N2}}-{\mathbf{N1}}+1$.
Parameters CC and ICOL have been included to give some indication of whether or not the vectors are nearly linearly independent, and their values should always be tested on exit from the routine. CC will be in the range $\left[0.0,1.0\right]$ and the closer CC is to $1.0$, the more likely the vector ICOL is to be linearly dependent on vectors N1 to ${\mathbf{ICOL}}-1$. Theoretically, when the vectors are linearly dependent, CC should be exactly $1.0$. In practice, because of rounding errors, it may be difficult to decide whether or not a value of CC close to $1.0$ indicates linear dependence. As a general guide a value of ${\mathbf{CC}}>0.99999$ usually indicates linear dependence, but examples exist which give ${\mathbf{CC}}>0.99999$ for linearly independent vectors. If one of the original vectors is zero or if, possibly due to rounding errors, an exactly zero vector is produced by the Gram–Schmidt process, then CC is set exactly to $1.0$ and the vector is not, of course, normalized. If more than one such vector occurs then ICOL references the last of these vectors.
If you are concerned about testing for near linear dependence in a set of vectors you may wish to consider using routine F08KBF (DGESVD).

## 9  Example

This example orthonormalizes columns 2, 3 and 4 of the matrix:
 $1 -2 3 1 -2 1 -2 -1 3 -2 1 5 4 1 5 3 .$

### 9.1  Program Text

Program Text (f05aafe.f90)

### 9.2  Program Data

Program Data (f05aafe.d)

### 9.3  Program Results

Program Results (f05aafe.r)