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_cgl_grid (d02uc)

## Purpose

nag_ode_bvp_ps_lin_cgl_grid (d02uc) returns the Chebyshev Gauss–Lobatto grid points on $\left[a,b\right]$.

## Syntax

[x, ifail] = d02uc(n, a, b)
[x, ifail] = nag_ode_bvp_ps_lin_cgl_grid(n, a, b)

## Description

nag_ode_bvp_ps_lin_cgl_grid (d02uc) returns the Chebyshev Gauss–Lobatto grid points on $\left[a,b\right]$. The Chebyshev Gauss–Lobatto points on $\left[-1,1\right]$ are computed as ${t}_{\mathit{i}}=-\mathrm{cos}\left(\frac{\left(\mathit{i}-1\right)\pi }{n}\right)$, for $\mathit{i}=1,2,\dots ,n+1$. The Chebyshev Gauss–Lobatto points on an arbitrary domain $\left[a,b\right]$ are:
 $xi = b-a 2 ti + a+b 2 , i=1,2,…,n+1 .$

## References

Trefethen L N (2000) Spectral Methods in MATLAB SIAM

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
$n$, where the number of grid points is $n+1$. This is also the largest order of Chebyshev polynomial in the Chebyshev series to be computed.
Constraint: ${\mathbf{n}}>0$ and n is even.
2:     $\mathrm{a}$ – double scalar
$a$, the lower bound of domain $\left[a,b\right]$.
Constraint: ${\mathbf{a}}<{\mathbf{b}}$.
3:     $\mathrm{b}$ – double scalar
$b$, the upper bound of domain $\left[a,b\right]$.
Constraint: ${\mathbf{b}}>{\mathbf{a}}$.

None.

### Output Parameters

1:     $\mathrm{x}\left({\mathbf{n}}+1\right)$ – double array
The Chebyshev Gauss–Lobatto grid points, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n+1$, on $\left[a,b\right]$.
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{n}}>0$.
Constraint: n is even.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{a}}<{\mathbf{b}}$.
${\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 Chebyshev Gauss–Lobatto grid points computed should be accurate to within a small multiple of machine precision.

The number of operations is of the order $n\mathrm{log}\left(n\right)$ and there are no internal memory requirements; thus the computation remains efficient and practical for very fine discretizations (very large values of $n$).

## Example

See Example in nag_ode_bvp_ps_lin_solve (d02ue).
```function d02uc_example

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

% On [0,4], Solve u + ux = f0(x); u(0) = 0
% where f) is such that u(x) = sin(10xcos^2x).
% Set up Chebyshev grid on [a,b]
a = 0;
b = 4;
n = int64(128);
[x, ifail] = d02uc(n, a, b);

% Get Chebyshev coeficients on grid for f0(x) = 1.
z = 10*x.*cos(x).^2;
f0 = sin(z) - 10*cos(x).^2.*cos(10*x.*cos(x).^2).*(2*x.*tan(x)-1);
[f0_c, ifail] = d02ua(n, f0);

% Set up problem definition for  u + ux = f0 [(1 1).(u ux) = f0]
f = [1, 1];
% subject to u(a) = 0  [(1 0).(u ux)(a) = 0]
y = [a];
B = [1, 0];
beta = 0;

% Solve in coefficient space using f0_c for rhs.
[B, f, uc, resid, ifail] = d02ue(...
n, a, b, f0_c, B, y, beta, f);

% Transform solution and derivative back to real space.
[u,  ifail] = d02ub(...
n, a, b, int64(0), uc(:, 1));
[ux, ifail] = d02ub(...
n, a, b, int64(1), uc(:, 2));

maxerr = max(abs(u - sin(z)));
fprintf('With n = %4d, maximum error in solution = %13.2e\n',n,maxerr);

% Plot solution
fig1 = figure;
plot(x,u,x,ux);
title('Solution of u + u_x = f_0 on [0,4]');
xlabel('x');
ylabel('u(x) and u_x(x)');
legend('u','u_x','Location','Northwest');

```
```d02uc example results

With n =  128, maximum error in solution =      5.33e-09
``` 