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_deriv (d02ud)

Purpose

nag_ode_bvp_ps_lin_cgl_deriv (d02ud) differentiates a function discretized on Chebyshev Gauss–Lobatto points. The grid points on which the function values are to be provided are normally returned by a previous call to nag_ode_bvp_ps_lin_cgl_grid (d02uc).

Syntax

[fd, ifail] = d02ud(n, f)
[fd, ifail] = nag_ode_bvp_ps_lin_cgl_deriv(n, f)

Description

nag_ode_bvp_ps_lin_cgl_deriv (d02ud) differentiates a function discretized on Chebyshev Gauss–Lobatto points on [1,1][-1,1]. The polynomial interpolation on Chebyshev points is equivalent to trigonometric interpolation on equally spaced points. Hence the differentiation on the Chebyshev points can be implemented by the Fast Fourier transform (FFT).
Given the function values f(xi)f(xi) on Chebyshev Gauss–Lobatto points xi = cos((i1)π / n) xi = - cos( (i-1) π / n ) , for i = 1,2,,n + 1i=1,2,,n+1, ff is differentiated with respect to xx by means of forward and backward FFTs on the function values f(xi)f(xi). nag_ode_bvp_ps_lin_cgl_deriv (d02ud) returns the computed derivative values f(xi)f(xi), for i = 1,2,,n + 1i=1,2,,n+1. The derivatives are computed with respect to the standard Chebyshev Gauss–Lobatto points on [1,1][-1,1]; for derivatives of a function on [a,b][a,b] the returned values have to be scaled by a factor 2 / (ba)2/(b-a).

References

Canuto C, Hussaini M Y, Quarteroni A and Zang T A (2006) Spectral Methods: Fundamentals in Single Domains Springer
Greengard L (1991) Spectral integration and two-point boundary value problems SIAM J. Numer. Anal. 28(4) 1071–80
Trefethen L N (2000) Spectral Methods in MATLAB SIAM

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
nn, where the number of grid points is n + 1n+1. The fast Fourier transform requires that the prime factorization of nn contain no more than 3030 prime factors.
Constraint: n > 0n>0 and n is even.
2:     f(n + 1n+1) – double array
The function values f(xi)f(xi), for i = 1,2,,n + 1i=1,2,,n+1

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     fd(n + 1n+1) – double array
The approximations to the derivatives of the function evaluated at the Chebyshev Gauss–Lobatto points. For functions defined on [a,b][a,b], the returned derivative values (corresponding to the domain [1,1][-1,1]) must be multiplied by the factor 2 / (ba)2/(b-a) to obtain the correct values on [a,b][a,b].
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = ifail=
Constraint: n > 0n>0.
Constraint: n is even.
  ifail = 999ifail=-999
Dynamic memory allocation failed.

Accuracy

The accuracy is close to machine precision for small numbers of grid points, typically less than 100. For larger numbers of grid points, the error in differentiation grows with the number of grid points. See Greengard (1991) for more details.

Further Comments

The number of operations is of the order n log(n) n log(n)  and the memory requirements are O(n)O(n); thus the computation remains efficient and practical for very fine discretizations (very large values of nn).

Example

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



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

% Evaluate function on Chebyshev grid
f = 2*x+exp(-x);

% Calculate derivative of function
[fd, ifail] = nag_ode_bvp_ps_lin_cgl_deriv(n, f);

scale = 2/(b-a);
fd = scale*fd;

% Print function and its derivatives
fprintf('\nOriginal function F and numerical derivative Fx\n');
fprintf('      x          F          Fx\n');
for i=1:17
  fprintf('%10.4f %10.4f %10.4f\n', x(i), f(i), fd(i));
end
 

Original function F and numerical derivative Fx
      x          F          Fx
    0.0000     1.0000     1.0000
    0.0144     1.0145     1.0143
    0.0571     1.0587     1.0555
    0.1264     1.1341     1.1187
    0.2197     1.2421     1.1972
    0.3333     1.3832     1.2835
    0.4630     1.5554     1.3706
    0.6037     1.7542     1.4532
    0.7500     1.9724     1.5276
    0.8963     2.2007     1.5919
    1.0370     2.4285     1.6455
    1.1667     2.6448     1.6886
    1.2803     2.8386     1.7221
    1.3736     3.0004     1.7468
    1.4429     3.1221     1.7638
    1.4856     3.1975     1.7736
    1.5000     3.2231     1.7769

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



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

% Evaluate function on Chebyshev grid
f = 2*x+exp(-x);

% Calculate derivative of function
[fd, ifail] = d02ud(n, f);

scale = 2/(b-a);
fd = scale*fd;

% Print function and its derivatives
fprintf('\nOriginal function F and numerical derivative Fx\n');
fprintf('      x          F          Fx\n');
for i=1:17
  fprintf('%10.4f %10.4f %10.4f\n', x(i), f(i), fd(i));
end
 

Original function F and numerical derivative Fx
      x          F          Fx
    0.0000     1.0000     1.0000
    0.0144     1.0145     1.0143
    0.0571     1.0587     1.0555
    0.1264     1.1341     1.1187
    0.2197     1.2421     1.1972
    0.3333     1.3832     1.2835
    0.4630     1.5554     1.3706
    0.6037     1.7542     1.4532
    0.7500     1.9724     1.5276
    0.8963     2.2007     1.5919
    1.0370     2.4285     1.6455
    1.1667     2.6448     1.6886
    1.2803     2.8386     1.7221
    1.3736     3.0004     1.7468
    1.4429     3.1221     1.7638
    1.4856     3.1975     1.7736
    1.5000     3.2231     1.7769


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