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_quad_weights (d02uy)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_ode_bvp_ps_lin_quad_weights (d02uy) obtains the weights for Clenshaw–Curtis quadrature at Chebyshev points. This allows for fast approximations of integrals for functions specified on Chebyshev Gauss–Lobatto points on -1,1.

Syntax

[w, ifail] = d02uy(n)
[w, ifail] = nag_ode_bvp_ps_lin_quad_weights(n)

Description

nag_ode_bvp_ps_lin_quad_weights (d02uy) obtains the weights for Clenshaw–Curtis quadrature at Chebyshev points.
Given the (Clenshaw–Curtis) weights wi, for i=0,1,,n, and function values fi=fti (where ti=-cosi×π/n, for i=0,1,,n, are the Chebyshev Gauss–Lobatto points), then -1 1 fx dx i=0 n wi fi .
For a function discretized on a Chebyshev Gauss–Lobatto grid on a,b the resultant summation must be multiplied by the factor b-a/2.

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.
Constraint: n>0 and n is even.

Optional Input Parameters

None.

Output Parameters

1:     wn+1 – double array
The Clenshaw–Curtis quadrature weights, wi, for i=0,1,,n.
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=-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 accuracy should be close to machine precision.

Further Comments

A real array of length 2n is internally allocated.

Example

This example approximates the integral -1 3 3 x2 dx using 65 Clenshaw–Curtis weights and a 65-point Chebyshev Gauss–Lobatto grid on -1,3.
function d02uy_example


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

n = int64(64);
a = -1;
b =  3;

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

% Get integrand values on grid
f = 3*x.^2;
scale = 0.5*(b-a);

% Get quadrature weights
[w, ifail] = d02uy(n);

% Evaluate apprimation to definite integral
integ = dot(w, f)*scale;

% Print solution
fprintf('Integral of f(x) from %4.1f to %4.1f = %7.4f\n', a, b, integ);
fprintf('\nError in approximation = %12.2e\n', integ-28);


d02uy example results

Integral of f(x) from -1.0 to  3.0 = 28.0000

Error in approximation =     3.55e-15

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