F01LEF (PDF version)
F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF01LEF

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

F01LEF computes an $LU$ factorization of a real tridiagonal matrix, using Gaussian elimination with partial pivoting.

## 2  Specification

 SUBROUTINE F01LEF ( N, A, LAMBDA, B, C, TOL, D, IPIV, IFAIL)
 INTEGER N, IPIV(N), IFAIL REAL (KIND=nag_wp) A(N), LAMBDA, B(N), C(N), TOL, D(N)

## 3  Description

The matrix $T-\lambda I$, where $T$ is a real $n$ by $n$ tridiagonal matrix, is factorized as
 $T-λI=PLU,$
where $P$ is a permutation matrix, $L$ is a unit lower triangular matrix with at most one nonzero subdiagonal element per column, and $U$ is an upper triangular matrix with at most two nonzero superdiagonal elements per column.
The factorization is obtained by Gaussian elimination with partial pivoting and implicit row scaling.
An indication of whether or not the matrix $T-\lambda I$ is nearly singular is returned in the $n$th element of the array IPIV. If it is important that $T-\lambda I$ is nonsingular, as is usually the case when solving a system of tridiagonal equations, then it is strongly recommended that ${\mathbf{IPIV}}\left(n\right)$ is inspected on return from F01LEF. (See the parameter IPIV and Section 8 for further details.)
The parameter $\lambda$ is included in the routine so that F01LEF may be used, in conjunction with F04LEF, to obtain eigenvectors of $T$ by inverse iteration.

## 4  References

Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the order of the matrix $T$.
Constraint: ${\mathbf{N}}\ge 1$.
2:     A(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the diagonal elements of $T$.
On exit: the diagonal elements of the upper triangular matrix $U$.
3:     LAMBDA – REAL (KIND=nag_wp)Input
On entry: the scalar $\lambda$. F01LEF factorizes $T-\lambda I$.
4:     B(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the superdiagonal elements of $T$, stored in ${\mathbf{B}}\left(2\right)$ to ${\mathbf{B}}\left(n\right)$; ${\mathbf{B}}\left(1\right)$ is not used.
On exit: the elements of the first superdiagonal of $U$, stored in ${\mathbf{B}}\left(2\right)$ to ${\mathbf{B}}\left(n\right)$.
5:     C(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the subdiagonal elements of $T$, stored in ${\mathbf{C}}\left(2\right)$ to ${\mathbf{C}}\left(n\right)$; ${\mathbf{C}}\left(1\right)$ is not used.
On exit: the subdiagonal elements of $L$, stored in ${\mathbf{C}}\left(2\right)$ to ${\mathbf{C}}\left(n\right)$.
6:     TOL – REAL (KIND=nag_wp)Input
On entry: a relative tolerance used to indicate whether or not the matrix ($T-\lambda I$) is nearly singular. TOL should normally be chosen as approximately the largest relative error in the elements of $T$. For example, if the elements of $T$ are correct to about $4$ significant figures, then TOL should be set to about $5×{10}^{-4}$. See Section 8 for further details on how TOL is used. If TOL is supplied as less than $\epsilon$, where $\epsilon$ is the machine precision, then the value $\epsilon$ is used in place of TOL.
7:     D(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the elements of the second superdiagonal of $U$, stored in ${\mathbf{D}}\left(3\right)$ to ${\mathbf{D}}\left(n\right)$; ${\mathbf{D}}\left(1\right)$ and ${\mathbf{D}}\left(2\right)$ are not used.
8:     IPIV(N) – INTEGER arrayOutput
On exit: details of the permutation matrix $P$. If an interchange occurred at the $k$th step of the elimination, then ${\mathbf{IPIV}}\left(k\right)=1$, otherwise ${\mathbf{IPIV}}\left(k\right)=0$. If a diagonal element of $U$ is small, indicating that $\left(T-\lambda I\right)$ is nearly singular, then the element ${\mathbf{IPIV}}\left(n\right)$ is returned as positive. Otherwise ${\mathbf{IPIV}}\left(n\right)$ is returned as $0$. See Section 8 for further details. If the application is such that it is important that $\left(T-\lambda I\right)$ is not nearly singular, then it is strongly recommended that ${\mathbf{IPIV}}\left(n\right)$ is inspected on return.
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{N}}<1$.

## 7  Accuracy

The computed factorization will satisfy the equation
 $PLU=T-λI+E,$
where
 $E1≤ 9×maxi≥j lij,lij2 ε T-λ I1$
where $\epsilon$ is the machine precision.

## 8  Further Comments

The time taken by F01LEF is approximately proportional to $n$.
The factorization of a tridiagonal matrix proceeds in $\left(n-1\right)$ steps, each step eliminating one subdiagonal element of the tridiagonal matrix. In order to avoid small pivot elements and to prevent growth in the size of the elements of $L$, rows $k$ and ($k+1$) will, if necessary, be interchanged at the $k$th step prior to the elimination.
The element ${\mathbf{IPIV}}\left(n\right)$ returns the smallest integer, $j$, for which
 $ujj≤T-λIj1×TOL,$
where ${‖{\left(T-\lambda I\right)}_{j}‖}_{1}$ denotes the sum of the absolute values of the $j$th row of the matrix ($T-\lambda I$). If no such $j$ exists, then ${\mathbf{IPIV}}\left(n\right)$ is returned as zero. If such a $j$ exists, then $\left|{u}_{jj}\right|$ is small and hence ($T-\lambda I$) is singular or nearly singular.
This routine may be followed by F04LEF to solve systems of tridiagonal equations. If you wish to solve single systems of tridiagonal equations you should be aware of F07CAF (DGTSV), which solves tridiagonal systems with a single call. F07CAF (DGTSV) requires less storage and will generally be faster than the combination of F01LEF and F04LEF, but no test for near singularity is included in F07CAF (DGTSV) and so it should only be used when the equations are known to be nonsingular.

## 9  Example

This example factorizes the tridiagonal matrix $T$ where
 $T= 3.0 2.1 0 0 0 3.4 2.3 -1.0 0 0 0 3.6 -5.0 1.9 0 0 0 7.0 -0.9 8.0 0 0 0 -6.0 7.1$
and then to solve the equations $Tx=y$, where
 $y= 2.7 -0.5 2.6 0.6 2.7$
by a call to F04LEF. The example program sets ${\mathbf{TOL}}=5×{10}^{-5}$ and, of course, sets ${\mathbf{LAMBDA}}=0$.

### 9.1  Program Text

Program Text (f01lefe.f90)

### 9.2  Program Data

Program Data (f01lefe.d)

### 9.3  Program Results

Program Results (f01lefe.r)

F01LEF (PDF version)
F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual