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_coeffs (d02ua)

Purpose

nag_ode_bvp_ps_lin_coeffs (d02ua) obtains the Chebyshev coefficients of a function discretized on Chebyshev Gauss–Lobatto points. The set of discretization points on which the function is evaluated is usually obtained by a previous call to nag_ode_bvp_ps_lin_cgl_grid (d02uc).

Syntax

[c, ifail] = d02ua(n, f)
[c, ifail] = nag_ode_bvp_ps_lin_coeffs(n, f)

Description

nag_ode_bvp_ps_lin_coeffs (d02ua) computes the coefficients cj${c}_{\mathit{j}}$, for j = 1,2,,n + 1$\mathit{j}=1,2,\dots ,n+1$, of the interpolating Chebyshev series
 (1/2) c1 T0 (x) + c2 T1 (x) + c3T2 (x) + ⋯ + cn + 1 Tn (x) , $12 c1 T0 (x-) + c2 T1 (x-) + c3T2 (x-) +⋯+ cn+1 Tn (x-) ,$
which interpolates the function f(x)$f\left(x\right)$ evaluated at the Chebyshev Gauss–Lobatto points
 xr = − cos((r − 1)π / n) ,   r = 1,2, … ,n + 1 . $x-r = - cos( (r-1) π/n ) , r=1,2,…,n+1 .$
Here Tj(x)${T}_{j}\left(\stackrel{-}{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree j$j$ with argument x$\stackrel{-}{x}$ defined on [1,1]$\left[-1,1\right]$. In terms of your original variable, x$x$ say, the input values at which the function values are to be provided are
 xr = − (1/2) (b − a) cos(π(r − 1) / n) + (1/2) (b + a) ,   r = 1,2, … ,n + 1 , ​ $xr = - 12 ( b - a ) cos( π(r-1) /n ) + 1 2 ( b + a ) , r=1,2,…,n+1 , ​$
where b$b$ and a$a$ are respectively the upper and lower ends of the range of x$x$ over which the function is required.

References

Canuto C (1988) Spectral Methods in Fluid Dynamics 502 Springer
Canuto C, Hussaini M Y, Quarteroni A and Zang T A (2006) Spectral Methods: Fundamentals in Single Domains Springer
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:     f(n + 1${\mathbf{n}}+1$) – double array
The function values f(xr)$f\left({x}_{\mathit{r}}\right)$, for r = 1,2,,n + 1$\mathit{r}=1,2,\dots ,n+1$.

None.

None.

Output Parameters

1:     c(n + 1${\mathbf{n}}+1$) – double array
The Chebyshev coefficients, cj${c}_{\mathit{j}}$, for j = 1,2,,n + 1$\mathit{j}=1,2,\dots ,n+1$.
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 > 1${\mathbf{n}}>1$.
Constraint: n is even.
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Accuracy

The Chebyshev coefficients 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 the memory requirements are O(n) $\mathit{O}\left(n\right)$; thus the computation remains efficient and practical for very fine discretizations (very large values of n$n$).

Example

```function nag_ode_bvp_ps_lin_coeffs_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 d02ua_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

```