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_cheb_eval (d02uz)

## Purpose

nag_ode_bvp_ps_lin_cheb_eval (d02uz) returns the value of the $k$th Chebyshev polynomial evaluated at a point $x\in \left[-1,1\right]$. nag_ode_bvp_ps_lin_cheb_eval (d02uz) is primarily a utility function for use by the Chebyshev boundary value problem solvers.

## Syntax

[t, ifail] = d02uz(k, x)
[t, ifail] = nag_ode_bvp_ps_lin_cheb_eval(k, x)

## Description

nag_ode_bvp_ps_lin_cheb_eval (d02uz) returns the value, $T$, of the $k$th Chebyshev polynomial evaluated at a point $x\in \left[-1,1\right]$; that is, $T=\mathrm{cos}\left(k×\mathrm{arccos}\left(x\right)\right)$.

## References

Trefethen L N (2000) Spectral Methods in MATLAB SIAM

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{k}$int64int32nag_int scalar
The order of the Chebyshev polynomial.
Constraint: ${\mathbf{k}}\ge 0$.
2:     $\mathrm{x}$ – double scalar
The point at which to evaluate the polynomial.
Constraint: $-1.0\le {\mathbf{x}}\le 1.0$.

None.

### Output Parameters

1:     $\mathrm{t}$ – double scalar
The value, $T$, of the Chebyshev polynomial order $k$ evaluated at $x$.
2:     $\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{k}}\ge 0$.
${\mathbf{ifail}}=2$
Constraint: $-1.0\le {\mathbf{x}}\le 1.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

The accuracy should be close to machine precision.

None.

## Example

A set of Chebyshev coefficients is obtained for the function $x+\mathrm{exp}\left(-x\right)$ defined on $\left[-0.24×\pi ,0.5×\pi \right]$ using nag_ode_bvp_ps_lin_cgl_grid (d02uc). At each of a set of new grid points in the domain of the function nag_ode_bvp_ps_lin_cheb_eval (d02uz) is used to evaluate each Chebshev polynomial in the series representation. The values obtained are multiplied to the Chebyshev coefficients and summed to obtain approximations to the given function at the new grid points.
```function d02uz_example

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

n = int64(16);
m = 9;
a = -0.24*pi;
b =  pi/2;

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

% Evaluate function on grid.and get interpolating Chebyshev coefficients
f = x + exp(-x);
[c, ifail] = d02ua(n, f);

% Evaluate Chebyshev series manually by evaluating each Chebyshev
% polynomial in turn at new equispaced (m+1) grid points.
% Chebyshev series on [-1,1] map of [a,b].
dmap  = 2/(m-1);
xmap  = [-1:dmap:1];
deven = (b-a)/(m-1);
xeven = [a:deven:b];

fprintf('    x_even     x_map      Sum(f)\n');
for i=1:m
for k=int64(0:n)
[t(k+1), ifail] = d02uz(k, xmap(i));
end
fseries(i) = dot(c,t);
end
fprintf('%10.4f %10.4f %10.4f\n', [xmap xeven fseries]');

```
```d02uz example results

x_even     x_map      Sum(f)
-1.0000    -0.7500    -0.5000
-0.2500     0.0000     0.2500
0.5000     0.7500     1.0000
-0.7540    -0.4634    -0.1728
0.1178     0.4084     0.6990
0.9896     1.2802     1.5708
1.3715     1.1261     1.0158
1.0067     1.0731     1.1961
1.3613     1.5582     1.7787
```