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)

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][-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 wiwi, for i = 0,1,,ni=0,1,,n, and function values fi = f(ti)fi=f(ti) (where ti = cos(i × π / n)ti=-cos(i×π/n), for i = 0,1,,ni=0,1,,n, are the Chebyshev Gauss–Lobatto points), then 11 f(x) dx i = 0n wi fi -1 1 f(x) dx i=0 n wi fi .
For a function discretized on a Chebyshev Gauss–Lobatto grid on [a,b][a,b] the resultant summation must be multiplied by the factor (ba) / 2(b-a)/2.

References

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

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     w(n + 1n+1) – double array
The Clenshaw–Curtis quadrature weights, wiwi, for i = 0,1,,ni=0,1,,n.
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 = 1ifail=1
Constraint: n > 0n>0.
Constraint: n is even.
  ifail = 999ifail=-999
Dynamic memory allocation failed.

Accuracy

The accuracy should be close to machine precision.

Further Comments

A real array of length 2n2n is internally allocated.

Example

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



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

% Set up problem right hand sides for grid
f = 3*x.^2;
scale = 0.5*(b-a);

% Solve on equally spaced grid
[w, ifail] = nag_ode_bvp_ps_lin_quad_weights(n);
integ = dot(w, f)*scale;
% Print solution
fprintf('\nf(x) and Integral weights\n');
fprintf('      x          f(x)        w\n');
for i=1:65
  fprintf('%10.4f %10.4f %10.4f\n', x(i), f(i), w(i));
end
fprintf('\nIntegral of f(x) from %g to %g = %g\n', a, b, integ);
 

f(x) and Integral weights
      x          f(x)        w
   -1.0000     3.0000     0.0002
   -0.9976     2.9856     0.0024
   -0.9904     2.9425     0.0048
   -0.9784     2.8715     0.0072
   -0.9616     2.7739     0.0096
   -0.9401     2.6512     0.0119
   -0.9139     2.5055     0.0143
   -0.8831     2.3395     0.0165
   -0.8478     2.1561     0.0188
   -0.8080     1.9585     0.0210
   -0.7638     1.7504     0.0231
   -0.7155     1.5356     0.0252
   -0.6629     1.3185     0.0273
   -0.6064     1.1032     0.0292
   -0.5460     0.8944     0.0311
   -0.4819     0.6967     0.0330
   -0.4142     0.5147     0.0347
   -0.3431     0.3532     0.0364
   -0.2688     0.2167     0.0379
   -0.1914     0.1099     0.0394
   -0.1111     0.0371     0.0408
   -0.0282     0.0024     0.0421
    0.0572     0.0098     0.0433
    0.1449     0.0630     0.0444
    0.2346     0.1652     0.0454
    0.3262     0.3193     0.0462
    0.4194     0.5278     0.0470
    0.5140     0.7927     0.0476
    0.6098     1.1156     0.0481
    0.7065     1.4976     0.0486
    0.8040     1.9391     0.0489
    0.9019     2.4401     0.0490
    1.0000     3.0000     0.0491
    1.0981     3.6177     0.0490
    1.1960     4.2915     0.0489
    1.2935     5.0191     0.0486
    1.3902     5.7978     0.0481
    1.4860     6.6242     0.0476
    1.5806     7.4946     0.0470
    1.6738     8.4046     0.0462
    1.7654     9.3496     0.0454
    1.8551    10.3243     0.0444
    1.9428    11.3233     0.0433
    2.0282    12.3409     0.0421
    2.1111    13.3707     0.0408
    2.1914    14.4067     0.0394
    2.2688    15.4422     0.0379
    2.3431    16.4706     0.0364
    2.4142    17.4853     0.0347
    2.4819    18.4795     0.0330
    2.5460    19.4467     0.0311
    2.6064    20.3802     0.0292
    2.6629    21.2737     0.0273
    2.7155    22.1211     0.0252
    2.7638    22.9165     0.0231
    2.8080    23.6542     0.0210
    2.8478    24.3292     0.0188
    2.8831    24.9366     0.0165
    2.9139    25.4721     0.0143
    2.9401    25.9319     0.0119
    2.9616    26.3127     0.0096
    2.9784    26.6118     0.0072
    2.9904    26.8269     0.0048
    2.9976    26.9567     0.0024
    3.0000    27.0000     0.0002

Integral of f(x) from -1 to 3 = 28

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



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

% Set up problem right hand sides for grid
f = 3*x.^2;
scale = 0.5*(b-a);

% Solve on equally spaced grid
[w, ifail] = d02uy(n);
integ = dot(w, f)*scale;
% Print solution
fprintf('\nf(x) and Integral weights\n');
fprintf('      x          f(x)        w\n');
for i=1:65
  fprintf('%10.4f %10.4f %10.4f\n', x(i), f(i), w(i));
end
fprintf('\nIntegral of f(x) from %g to %g = %g\n', a, b, integ);
 

f(x) and Integral weights
      x          f(x)        w
   -1.0000     3.0000     0.0002
   -0.9976     2.9856     0.0024
   -0.9904     2.9425     0.0048
   -0.9784     2.8715     0.0072
   -0.9616     2.7739     0.0096
   -0.9401     2.6512     0.0119
   -0.9139     2.5055     0.0143
   -0.8831     2.3395     0.0165
   -0.8478     2.1561     0.0188
   -0.8080     1.9585     0.0210
   -0.7638     1.7504     0.0231
   -0.7155     1.5356     0.0252
   -0.6629     1.3185     0.0273
   -0.6064     1.1032     0.0292
   -0.5460     0.8944     0.0311
   -0.4819     0.6967     0.0330
   -0.4142     0.5147     0.0347
   -0.3431     0.3532     0.0364
   -0.2688     0.2167     0.0379
   -0.1914     0.1099     0.0394
   -0.1111     0.0371     0.0408
   -0.0282     0.0024     0.0421
    0.0572     0.0098     0.0433
    0.1449     0.0630     0.0444
    0.2346     0.1652     0.0454
    0.3262     0.3193     0.0462
    0.4194     0.5278     0.0470
    0.5140     0.7927     0.0476
    0.6098     1.1156     0.0481
    0.7065     1.4976     0.0486
    0.8040     1.9391     0.0489
    0.9019     2.4401     0.0490
    1.0000     3.0000     0.0491
    1.0981     3.6177     0.0490
    1.1960     4.2915     0.0489
    1.2935     5.0191     0.0486
    1.3902     5.7978     0.0481
    1.4860     6.6242     0.0476
    1.5806     7.4946     0.0470
    1.6738     8.4046     0.0462
    1.7654     9.3496     0.0454
    1.8551    10.3243     0.0444
    1.9428    11.3233     0.0433
    2.0282    12.3409     0.0421
    2.1111    13.3707     0.0408
    2.1914    14.4067     0.0394
    2.2688    15.4422     0.0379
    2.3431    16.4706     0.0364
    2.4142    17.4853     0.0347
    2.4819    18.4795     0.0330
    2.5460    19.4467     0.0311
    2.6064    20.3802     0.0292
    2.6629    21.2737     0.0273
    2.7155    22.1211     0.0252
    2.7638    22.9165     0.0231
    2.8080    23.6542     0.0210
    2.8478    24.3292     0.0188
    2.8831    24.9366     0.0165
    2.9139    25.4721     0.0143
    2.9401    25.9319     0.0119
    2.9616    26.3127     0.0096
    2.9784    26.6118     0.0072
    2.9904    26.8269     0.0048
    2.9976    26.9567     0.0024
    3.0000    27.0000     0.0002

Integral of f(x) from -1 to 3 = 28


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