hide long namesshow long names
hide short namesshow short names
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)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_ode_bvp_ps_lin_cgl_grid (d02uc) returns the Chebyshev Gauss–Lobatto grid points on a,b.

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. The Chebyshev Gauss–Lobatto points on -1,1 are computed as ti = - cos i-1π n , for i=1,2,,n+1. The Chebyshev Gauss–Lobatto points on an arbitrary domain a,b  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:     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: n>0 and n is even.
2:     a – double scalar
a, the lower bound of domain a,b.
Constraint: a<b.
3:     b – double scalar
b, the upper bound of domain a,b.
Constraint: b>a.

Optional Input Parameters

None.

Output Parameters

1:     xn+1 – double array
The Chebyshev Gauss–Lobatto grid points, xi, for i=1,2,,n+1, on a,b.
2:     ifail int64int32nag_int scalar
ifail=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
Constraint: n>0.
Constraint: n is even.
   ifail=2
Constraint: a<b.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   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.

Further Comments

The number of operations is of the order n logn  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
d02uc_fig1.png

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–2015