# NAG Library Routine Document

## 1Purpose

f04fef solves the Yule–Walker equations for a real symmetric positive definite Toeplitz system.

## 2Specification

Fortran Interface
 Subroutine f04fef ( n, t, x, p, v, work,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: t(0:n) Real (Kind=nag_wp), Intent (Inout) :: p(*), v(*) Real (Kind=nag_wp), Intent (Out) :: x(n), vlast, work(n-1) Logical, Intent (In) :: wantp, wantv
#include nagmk26.h
 void f04fef_ (const Integer *n, const double t[], double x[], const logical *wantp, double p[], const logical *wantv, double v[], double *vlast, double work[], Integer *ifail)

## 3Description

f04fef solves the equations
 $Tx=-t,$
where $T$ is the $n$ by $n$ symmetric positive definite Toeplitz matrix
 $T= τ0 τ1 τ2 … τn-1 τ1 τ0 τ1 … τn-2 τ2 τ1 τ0 … τn-3 . . . . τn-1 τn-2 τn-3 … τ0$
and $t$ is the vector
 $tT=τ1,τ2…τn.$
The routine uses the method of Durbin (see Durbin (1960) and Golub and Van Loan (1996)). Optionally the mean square prediction errors and/or the partial correlation coefficients for each step can be returned.

## 4References

Bunch J R (1985) Stability of methods for solving Toeplitz systems of equations SIAM J. Sci. Statist. Comput. 6 349–364
Bunch J R (1987) The weak and strong stability of algorithms in numerical linear algebra Linear Algebra Appl. 88/89 49–66
Cybenko G (1980) The numerical stability of the Levinson–Durbin algorithm for Toeplitz systems of equations SIAM J. Sci. Statist. Comput. 1 303–319
Durbin J (1960) The fitting of time series models Rev. Inst. Internat. Stat. 28 233
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: the order of the Toeplitz matrix $T$.
Constraint: ${\mathbf{n}}\ge 0$. When ${\mathbf{n}}=0$, an immediate return is effected.
2:     $\mathbf{t}\left(0:{\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{t}}\left(0\right)$ must contain the value ${\tau }_{0}$ of the diagonal elements of $T$, and the remaining n elements of t must contain the elements of the vector $t$.
Constraint: ${\mathbf{t}}\left(0\right)>0.0$. Note that if this is not true, the Toeplitz matrix cannot be positive definite.
3:     $\mathbf{x}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the solution vector $x$.
4:     $\mathbf{wantp}$ – LogicalInput
On entry: must be set to .TRUE. if the partial (auto)correlation coefficients are required, and must be set to .FALSE. otherwise.
5:     $\mathbf{p}\left(*\right)$ – Real (Kind=nag_wp) arrayOutput
Note: the dimension of the array p must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{wantp}}=\mathrm{.TRUE.}$, and at least $1$ otherwise.
On exit: with wantp as .TRUE., the $i$th element of p contains the partial (auto)correlation coefficient, or reflection coefficient, ${p}_{i}$ for the $i$th step. (See Section 9 and Chapter G13.) If wantp is .FALSE., p is not referenced. Note that in any case, ${x}_{n}={p}_{n}$.
6:     $\mathbf{wantv}$ – LogicalInput
On entry: must be set to .TRUE. if the mean square prediction errors are required, and must be set to .FALSE. otherwise.
7:     $\mathbf{v}\left(*\right)$ – Real (Kind=nag_wp) arrayOutput
Note: the dimension of the array v must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{wantv}}=\mathrm{.TRUE.}$, and at least $1$ otherwise.
On exit: with wantv as .TRUE., the $i$th element of v contains the mean square prediction error, or predictor error variance ratio, ${v}_{i}$, for the $i$th step. (See Section 9 and Chapter G13.) If wantv is .FALSE., v is not referenced.
8:     $\mathbf{vlast}$ – Real (Kind=nag_wp)Output
On exit: the value of ${v}_{n}$, the mean square prediction error for the final step.
9:     $\mathbf{work}\left({\mathbf{n}}-1\right)$ – Real (Kind=nag_wp) arrayWorkspace
10:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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, because for this routine the values of the output arguments may be useful even if ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Note: f04fef may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{ifail}}=-1$
 On entry, ${\mathbf{n}}<0$, or ${\mathbf{t}}\left(0\right)\le 0.0$.
${\mathbf{ifail}}>0$
The principal minor of order (${\mathbf{ifail}}+1$) of the Toeplitz matrix is not positive definite to working accuracy. If, on exit, ${x}_{{\mathbf{ifail}}}$ is close to unity, the principal minor was close to being singular, and the sequence ${\tau }_{0},{\tau }_{1},\dots ,{\tau }_{{\mathbf{ifail}}}$ may be a valid sequence nevertheless. The first ifail elements of x return the solution of the equations
 $Tifailx=-τ1,τ2,…,τifailT,$
where ${T}_{{\mathbf{ifail}}}$ is the ifailth principal minor of $T$. Similarly, if wantp and/or wantv are true, then p and/or v return the first ifail elements of p and v respectively and vlast returns ${v}_{{\mathbf{ifail}}}$. In particular if ${\mathbf{ifail}}={\mathbf{n}}$, then the solution of the equations $Tx=-t$ is returned in x, but ${\tau }_{{\mathbf{n}}}$ is such that ${T}_{{\mathbf{n}}+1}$ would not be positive definite to working accuracy.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The computed solution of the equations certainly satisfies
 $r=Tx+t,$
where ${‖r‖}_{1}$ is approximately bounded by
 $r1≤cε ∏i=1n1+pi-1 ,$
$c$ being a modest function of $n$ and $\epsilon$ being the machine precision. This bound is almost certainly pessimistic, but it has not yet been established whether or not the method of Durbin is backward stable. If $\left|{p}_{n}\right|$ is close to one, then the Toeplitz matrix is probably ill-conditioned and hence only just positive definite. For further information on stability issues see Bunch (1985), Bunch (1987), Cybenko (1980) and Golub and Van Loan (1996). The following bounds on ${‖{{\mathbf{t}}}^{-1}‖}_{1}$ hold:
 $max 1 vn-1 , 1 ∏ i=1 n-1 1-pi ≤ T-11 ≤ ∏ i=1 n-1 1+pi 1-pi .$
Note:  ${v}_{n}<{v}_{n-1}$. The norm of ${T}^{-1}$ may also be estimated using routine f04ydf.

## 8Parallelism and Performance

f04fef 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.

The number of floating-point operations used by f04fef is approximately $2{n}^{2}$, independent of the values of wantp and wantv.
The mean square prediction error, ${v}_{i}$, is defined as
 $vi=τ0+τ1τ2…τi-1yi-1/τ0,$
where ${y}_{i}$ is the solution of the equations
 $Tiyi=-τ1τ2…τiT$
and the partial correlation coefficient, ${p}_{i}$, is defined as the $i$th element of ${y}_{i}$. Note that ${v}_{i}=\left(1-{p}_{i}^{2}\right){v}_{i-1}$.

## 10Example

This example finds the solution of the Yule–Walker equations $Tx=-t$, where
 $T= 4 3 2 1 3 4 3 2 2 3 4 3 1 2 3 4 and t= 3 2 1 0 .$

### 10.1Program Text

Program Text (f04fefe.f90)

### 10.2Program Data

Program Data (f04fefe.d)

### 10.3Program Results

Program Results (f04fefe.r)

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