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$k$th Chebyshev polynomial evaluated at a point x[1,1]$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$T$, of the k$k$th Chebyshev polynomial evaluated at a point x[1,1]$x\in \left[-1,1\right]$; that is, T = cos(k × arccos(x))$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:     k – int64int32nag_int scalar
The order of the Chebyshev polynomial.
Constraint: k0${\mathbf{k}}\ge 0$.
2:     x – double scalar
The point at which to evaluate the polynomial.
Constraint: 1.0x1.0$-1.0\le {\mathbf{x}}\le 1.0$.

None.

None.

### Output Parameters

1:     t – double scalar
The value, T$T$, of the Chebyshev polynomial order k$k$ evaluated at x$x$.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

ifail = 1${\mathbf{ifail}}=1$
Constraint: k0${\mathbf{k}}\ge 0$.
ifail = 2${\mathbf{ifail}}=2$
Constraint: 1.0x1.0$-1.0\le {\mathbf{x}}\le 1.0$.

## Accuracy

The accuracy should be close to machine precision.

None.

## Example

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

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

% Evaluate function on grid.and get interpolating Chebyshev coefficients
f = x + exp(-x);
[c, ifail] = nag_ode_bvp_ps_lin_coeffs(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].
xmap  = -1;
dmap  = 2/(m-1);
xeven = a;
deven = (b-a)/(m-1);

fprintf('\n    x_even     x_map      Sum\n');
for i=1:m
fseries = 0;
for k=0:double(n)
[t, ifail] = nag_ode_bvp_ps_lin_cheb_eval(int64(k), xmap);
fseries = fseries + c(k+1)*t;
end
fprintf('%10.4f %10.4f %10.4f\n', xmap, xeven, fseries);
xmap = min(1, xmap+dmap);
xeven = xeven + deven;
end
```
```

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

```
```function d02uz_example
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].
xmap  = -1;
dmap  = 2/(m-1);
xeven = a;
deven = (b-a)/(m-1);

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

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

```