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

## 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 $\left[-1,1\right]$.

## Syntax

[w, ifail] = d02uy(n)

## Description

Given the (Clenshaw–Curtis) weights ${w}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$, and function values ${f}_{\mathit{i}}=f\left({t}_{\mathit{i}}\right)$ (where ${t}_{\mathit{i}}=-\mathrm{cos}\left(\mathit{i}×\pi /n\right)$, for $\mathit{i}=0,1,\dots ,n$, are the Chebyshev Gauss–Lobatto points), then $\underset{-1}{\overset{1}{\int }}f\left(x\right)dx\approx \sum _{\mathit{i}=0}^{n}{w}_{i}{f}_{i}$.
For a function discretized on a Chebyshev Gauss–Lobatto grid on $\left[a,b\right]$ the resultant summation must be multiplied by the factor $\left(b-a\right)/2$.

## References

Trefethen L N (2000) Spectral Methods in MATLAB SIAM

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
$n$, where the number of grid points is $n+1$.
Constraint: ${\mathbf{n}}>0$ and n is even.

None.

### Output Parameters

1:     $\mathrm{w}\left({\mathbf{n}}+1\right)$ – double array
The Clenshaw–Curtis quadrature weights, ${w}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{n}}>0$.
Constraint: n is even.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The accuracy should be close to machine precision.

A real array of length $2n$ is internally allocated.

## Example

This example approximates the integral $\underset{-1}{\overset{3}{\int }}3{x}^{2}dx$ using $65$ Clenshaw–Curtis weights and a $\mathrm{65}$-point Chebyshev Gauss–Lobatto grid on $\left[-1,3\right]$.
```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);

[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
```