D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD02UWF

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

D02UWF interpolates from a set of function values on a supplied grid onto a set of values for a uniform grid on the same range. The interpolation is performed using barycentric Lagrange interpolation. D02UWF is primarily a utility routine to map a set of function values specified on a Chebyshev Gauss–Lobatto grid onto a uniform grid.

## 2  Specification

 SUBROUTINE D02UWF ( N, NIP, X, F, XIP, FIP, IFAIL)
 INTEGER N, NIP, IFAIL REAL (KIND=nag_wp) X(N+1), F(N+1), XIP(NIP), FIP(NIP)

## 3  Description

D02UWF interpolates from a set of $n+1$ function values, $f\left({x}_{\mathit{i}}\right)$, on a supplied grid, ${x}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$, onto a set of $m$ values, $\stackrel{^}{f}\left({\stackrel{^}{x}}_{\mathit{j}}\right)$, on a uniform grid, ${\stackrel{^}{x}}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,m$. The image $\stackrel{^}{x}$ has the same range as $x$, so that ${\stackrel{^}{x}}_{\mathit{j}}={x}_{\mathrm{min}}+\left(\left(\mathit{j}-1\right)/\left(m-1\right)\right)×\left({x}_{\mathrm{max}}-{x}_{\mathrm{min}}\right)$, for $\mathit{j}=1,2,\dots ,m$. The interpolation is performed using barycentric Lagrange interpolation as described in Berrut and Trefethen (2004).
D02UWF is primarily a utility routine to map a set of function values specified on a Chebyshev Gauss–Lobatto grid computed by D02UCF onto an evenly-spaced grid with the same range as the original grid.

## 4  References

Berrut J P and Trefethen L N (2004) Barycentric lagrange interpolation SIAM Rev. 46(3) 501–517

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, where the number of grid points for the input data is $n+1$.
Constraint: ${\mathbf{N}}>0$ and N is even.
2:     NIP – INTEGERInput
On entry: the number, $m$, of grid points in the uniform mesh $\stackrel{^}{x}$ onto which function values are interpolated. If ${\mathbf{NIP}}=1$ then on successful exit from D02UWF, ${\mathbf{FIP}}\left(1\right)$ will contain the value $f\left({x}_{n}\right)$.
Constraint: ${\mathbf{NIP}}>0$.
3:     X(${\mathbf{N}}+1$) – REAL (KIND=nag_wp) arrayInput
On entry: the grid points, ${x}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$, at which the function is specified.
Usually this should be the array of Chebyshev Gauss–Lobatto points returned in D02UCF.
4:     F(${\mathbf{N}}+1$) – REAL (KIND=nag_wp) arrayInput
On entry: the function values, $f\left({x}_{\mathit{i}}\right)$, for $\mathit{i}=0,1,\dots ,n$.
5:     XIP(NIP) – REAL (KIND=nag_wp) arrayOutput
On exit: the evenly-spaced grid points, ${\stackrel{^}{x}}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,m$.
6:     FIP(NIP) – REAL (KIND=nag_wp) arrayOutput
On exit: the set of interpolated values $\stackrel{^}{f}\left({\stackrel{^}{x}}_{\mathit{j}}\right)$, for $\mathit{j}=1,2,\dots ,m$. Here $\stackrel{^}{f}\left({\stackrel{^}{x}}_{\mathit{j}}\right)\approx f\left(x={\stackrel{^}{x}}_{\mathit{j}}\right)$.
7:     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

${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}\le 0$ or N is odd.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{NIP}}\le 0$.

## 7  Accuracy

D02UWF is intended, primarily, for use with Chebyshev Gauss–Lobatto input grids. For such input grids and for well-behaved functions (no discontinuities, peaks or cusps), the accuracy should be a small multiple of machine precision.

None.

## 9  Example

This example interpolates the function $x+\mathrm{cos}\left(5x\right)$, as specified on a $65$-point Gauss–Lobatto grid on $\left[-1,1\right]$, onto a coarse uniform grid.

### 9.1  Program Text

Program Text (d02uwfe.f90)

### 9.2  Program Data

Program Data (d02uwfe.d)

### 9.3  Program Results

Program Results (d02uwfe.r)