Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
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 [a,b]$\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 [a,b]$\left[a,b\right]$. The Chebyshev Gauss–Lobatto points on [1,1]$\left[-1,1\right]$ are computed as ti = cos(((i1)π)/n) ${t}_{\mathit{i}}=-\mathrm{cos}\left(\frac{\left(\mathit{i}-1\right)\pi }{n}\right)$, for i = 1,2,,n + 1$\mathit{i}=1,2,\dots ,n+1$. The Chebyshev Gauss–Lobatto points on an arbitrary domain [a,b] $\left[a,b\right]$ are:
 xi = (b − a)/2 ti + (a + b)/2 ,   i = 1,2, … ,n + 1 . $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:     n – int64int32nag_int scalar
n$n$, where the number of grid points is n + 1$n+1$. This is also the largest order of Chebyshev polynomial in the Chebyshev series to be computed.
Constraint: n > 0${\mathbf{n}}>0$ and n is even.
2:     a – double scalar
a$a$, the lower bound of domain [a,b]$\left[a,b\right]$.
Constraint: a < b${\mathbf{a}}<{\mathbf{b}}$.
3:     b – double scalar
b$b$, the upper bound of domain [a,b]$\left[a,b\right]$.
Constraint: b > a${\mathbf{b}}>{\mathbf{a}}$.

None.

None.

### Output Parameters

1:     x(n + 1${\mathbf{n}}+1$) – double array
The Chebyshev Gauss–Lobatto grid points, xi${x}_{\mathit{i}}$, for i = 1,2,,n + 1$\mathit{i}=1,2,\dots ,n+1$, on [a,b]$\left[a,b\right]$.
2:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
Constraint: n > 0${\mathbf{n}}>0$.
Constraint: n is even.
ifail = 2${\mathbf{ifail}}=2$
Constraint: a < b${\mathbf{a}}<{\mathbf{b}}$.

## 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 log(n) $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$n$).

## Example

```function nag_ode_bvp_ps_lin_cgl_grid_example
n = int64(16);
a = 0;
b = 1.5;

% Set up boundary condition on left side of domain
y = [a];
% Set up Dirichlet condition using exact solution at x=a.
bmat = [1, 0];
bvec = exp(-a-1) + 1;

% Set up problem definition
f = [1, 1];

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

% Set up problem right hand sides for grid and transform
f0 = ones(17, 1);
[c, ifail] = nag_ode_bvp_ps_lin_coeffs(n, f0);

% Solve in coefficient space
[bmat, f, uc, resid, ifail] = nag_ode_bvp_ps_lin_solve(n, a, b, c, bmat, y, bvec, f);
% Transform solution and derivative back to real space.
[u,  ifail] = nag_ode_bvp_ps_lin_cgl_vals(n, a, b, int64(0), uc(:, 1));
[ux, ifail] = nag_ode_bvp_ps_lin_cgl_vals(n, a, b, int64(1), uc(:, 2));

% Print Solution
fprintf('\nNumerical solution U and derivative Ux\n');
fprintf('      x          U          Ux\n');
for i=1:17
fprintf('%10.4f %10.4f %10.4f\n', x(i), u(i), ux(i));
end
```
```

Numerical solution U and derivative Ux
x          U          Ux
0.0000     1.3679    -0.3679
0.0144     1.3626    -0.3626
0.0571     1.3475    -0.3475
0.1264     1.3242    -0.3242
0.2197     1.2953    -0.2953
0.3333     1.2636    -0.2636
0.4630     1.2315    -0.2315
0.6037     1.2012    -0.2012
0.7500     1.1738    -0.1738
0.8963     1.1501    -0.1501
1.0370     1.1304    -0.1304
1.1667     1.1146    -0.1146
1.2803     1.1023    -0.1023
1.3736     1.0931    -0.0931
1.4429     1.0869    -0.0869
1.4856     1.0833    -0.0833
1.5000     1.0821    -0.0821

```
```function d02uc_example
n = int64(16);
a = 0;
b = 1.5;

% Set up boundary condition on left side of domain
y = [a];
% Set up Dirichlet condition using exact solution at x=a.
bmat = [1, 0];
bvec = exp(-a-1) + 1;

% Set up problem definition
f = [1, 1];

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

% Set up problem right hand sides for grid and transform
f0 = ones(17, 1);
[c, ifail] = d02ua(n, f0);

% Solve in coefficient space
[bmat, f, uc, resid, ifail] = d02ue(n, a, b, c, bmat, y, bvec, 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));

% Print Solution
fprintf('\nNumerical solution U and derivative Ux\n');
fprintf('      x          U          Ux\n');
for i=1:17
fprintf('%10.4f %10.4f %10.4f\n', x(i), u(i), ux(i));
end
```
```

Numerical solution U and derivative Ux
x          U          Ux
0.0000     1.3679    -0.3679
0.0144     1.3626    -0.3626
0.0571     1.3475    -0.3475
0.1264     1.3242    -0.3242
0.2197     1.2953    -0.2953
0.3333     1.2636    -0.2636
0.4630     1.2315    -0.2315
0.6037     1.2012    -0.2012
0.7500     1.1738    -0.1738
0.8963     1.1501    -0.1501
1.0370     1.1304    -0.1304
1.1667     1.1146    -0.1146
1.2803     1.1023    -0.1023
1.3736     1.0931    -0.0931
1.4429     1.0869    -0.0869
1.4856     1.0833    -0.0833
1.5000     1.0821    -0.0821

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013