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$.
Trefethen L N (2000) Spectral Methods in MATLAB SIAM

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, where the number of grid points is $n+1$.
Constraint: ${\mathbf{N}}>0$ and N is even.
2:     W(${\mathbf{N}}+1$) – REAL (KIND=nag_wp) arrayOutput
On exit: the Clenshaw–Curtis quadrature weights, ${w}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$.
3:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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 parameter, 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}}={\mathbf{0}}$ or $-{\mathbf{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}}\le 0$ or N is odd.
${\mathbf{IFAIL}}=-999$
Internal memory allocation failed.

## 7  Accuracy

The accuracy should be close to machine precision.

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

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

### 9.1  Program Text

Program Text (d02uyfe.f90)

### 9.2  Program Data

Program Data (d02uyfe.d)

### 9.3  Program Results

Program Results (d02uyfe.r)