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_ode_bvp_ps_lin_grid_vals (d02uw)

## Purpose

nag_ode_bvp_ps_lin_grid_vals (d02uw) 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. nag_ode_bvp_ps_lin_grid_vals (d02uw) is primarily a utility function to map a set of function values specified on a Chebyshev Gauss–Lobatto grid onto a uniform grid.

## Syntax

[xip, fip, ifail] = d02uw(n, nip, x, f)
[xip, fip, ifail] = nag_ode_bvp_ps_lin_grid_vals(n, nip, x, f)

## Description

nag_ode_bvp_ps_lin_grid_vals (d02uw) 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).
nag_ode_bvp_ps_lin_grid_vals (d02uw) is primarily a utility function to map a set of function values specified on a Chebyshev Gauss–Lobatto grid computed by nag_ode_bvp_ps_lin_cgl_grid (d02uc) onto an evenly-spaced grid with the same range as the original grid.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
$n$, where the number of grid points for the input data is $n+1$.
Constraint: ${\mathbf{n}}>0$ and n is even.
2:     $\mathrm{nip}$int64int32nag_int scalar
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 nag_ode_bvp_ps_lin_grid_vals (d02uw), ${\mathbf{fip}}\left(1\right)$ will contain the value $f\left({x}_{n}\right)$.
Constraint: ${\mathbf{nip}}>0$.
3:     $\mathrm{x}\left({\mathbf{n}}+1\right)$ – double array
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 nag_ode_bvp_ps_lin_cgl_grid (d02uc).
4:     $\mathrm{f}\left({\mathbf{n}}+1\right)$ – double array
The function values, $f\left({x}_{\mathit{i}}\right)$, for $\mathit{i}=0,1,\dots ,n$.

None.

### Output Parameters

1:     $\mathrm{xip}\left({\mathbf{nip}}\right)$ – double array
The evenly-spaced grid points, ${\stackrel{^}{x}}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,m$.
2:     $\mathrm{fip}\left({\mathbf{nip}}\right)$ – double array
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)$.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{n}}>0$.
Constraint: n is even.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{nip}}>0$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

nag_ode_bvp_ps_lin_grid_vals (d02uw) 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.

## 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.
```function d02uw_example

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

n   = int64(64);
a = -1;
b =  1;

% Set up Chebyshev grid
[x, ifail] = d02uc(n, a, b);

% Set up function on grid
f = x + cos(5*x);

% Interpolate onto smaller equally spaced grid
nip = int64(17);
[xip, fip, ifail] = d02uw(n, nip, x, f);

% Display interpolated values
fprintf('\nInterpolated function values\n');
fprintf('      x          F\n');
fprintf('%10.4f %10.4f \n', [xip fip]');

```
```d02uw example results

Interpolated function values
x          F
-1.0000    -0.7163
-0.8750    -1.2060
-0.7500    -1.5706
-0.6250    -1.6249
-0.5000    -1.3011
-0.3750    -0.6745
-0.2500     0.0653
-0.1250     0.6860
0.0000     1.0000
0.1250     0.9360
0.2500     0.5653
0.3750     0.0755
0.5000    -0.3011
0.6250    -0.3749
0.7500    -0.0706
0.8750     0.5440
1.0000     1.2837
```