D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD02UYF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

D02UYF 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]$.

## 2  Specification

 SUBROUTINE D02UYF ( N, W, IFAIL)
 INTEGER N, IFAIL REAL (KIND=nag_wp) W(N+1)

## 3  Description

D02UYF obtains the weights for Clenshaw–Curtis quadrature at Chebyshev points.
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$.

## 4  References

Trefethen L N (2000) Spectral Methods in MATLAB SIAM

## 5  Arguments

1:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, where the number of grid points is $n+1$.
Constraint: ${\mathbf{N}}>0$ and N is even.
2:     $\mathrm{W}\left({\mathbf{N}}+1\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the Clenshaw–Curtis quadrature weights, ${w}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$.
3:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{N}}>0$.
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: N is even.
${\mathbf{IFAIL}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7  Accuracy

The accuracy should be close to machine precision.

## 8  Parallelism and Performance

D02UYF is not threaded in any implementation.

## 9  Further Comments

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

## 10  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]$.

### 10.1  Program Text

Program Text (d02uyfe.f90)

### 10.2  Program Data

Program Data (d02uyfe.d)

### 10.3  Program Results

Program Results (d02uyfe.r)