E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02AJF

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

E02AJF determines the coefficients in the Chebyshev series representation of the indefinite integral of a polynomial given in Chebyshev series form.

## 2  Specification

 SUBROUTINE E02AJF ( NP1, XMIN, XMAX, A, IA1, LA, QATM1, AINTC, IAINT1, LAINT, IFAIL)
 INTEGER NP1, IA1, LA, IAINT1, LAINT, IFAIL REAL (KIND=nag_wp) XMIN, XMAX, A(LA), QATM1, AINTC(LAINT)

## 3  Description

E02AJF forms the polynomial which is the indefinite integral of a given polynomial. Both the original polynomial and its integral are represented in Chebyshev series form. If supplied with the coefficients ${a}_{i}$, for $\mathit{i}=0,1,\dots ,n$, of a polynomial $p\left(x\right)$ of degree $n$, where
 $px=12a0+a1T1x-+⋯+anTnx-,$
the routine returns the coefficients ${a}_{i}^{\prime }$, for $\mathit{i}=0,1,\dots ,n+1$, of the polynomial $q\left(x\right)$ of degree $n+1$, where
 $qx=12a0′+a1′T1x-+⋯+an+1′Tn+1x-,$
and
 $qx=∫pxdx.$
Here ${T}_{j}\left(\stackrel{-}{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree $j$ with argument $\stackrel{-}{x}$. It is assumed that the normalized variable $\stackrel{-}{x}$ in the interval $\left[-1,+1\right]$ was obtained from your original variable $x$ in the interval $\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$ by the linear transformation
 $x-=2x-xmax+xmin xmax-xmin$
and that you require the integral to be with respect to the variable $x$. If the integral with respect to $\stackrel{-}{x}$ is required, set ${x}_{\mathrm{max}}=1$ and ${x}_{\mathrm{min}}=-1$.
Values of the integral can subsequently be computed, from the coefficients obtained, by using E02AKF.
The method employed is that of Chebyshev series (see Chapter 8 of Modern Computing Methods (1961)), modified for integrating with respect to $x$. Initially taking ${a}_{n+1}={a}_{n+2}=0$, the routine forms successively
 $ai′=ai-1-ai+1 2i ×xmax-xmin2, i=n+1,n,…,1.$
The constant coefficient ${a}_{0}^{\prime }$ is chosen so that $q\left(x\right)$ is equal to a specified value, QATM1, at the lower end point of the interval on which it is defined, i.e., $\stackrel{-}{x}=-1$, which corresponds to $x={x}_{\mathrm{min}}$.

## 4  References

Modern Computing Methods (1961) Chebyshev-series NPL Notes on Applied Science 16 (2nd Edition) HMSO

## 5  Parameters

1:     NP1 – INTEGERInput
On entry: $n+1$, where $n$ is the degree of the given polynomial $p\left(x\right)$. Thus NP1 is the number of coefficients in this polynomial.
Constraint: ${\mathbf{NP1}}\ge 1$.
2:     XMIN – REAL (KIND=nag_wp)Input
3:     XMAX – REAL (KIND=nag_wp)Input
On entry: the lower and upper end points respectively of the interval $\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$. The Chebyshev series representation is in terms of the normalized variable $\stackrel{-}{x}$, where
 $x-=2x-xmax+xmin xmax-xmin .$
Constraint: ${\mathbf{XMAX}}>{\mathbf{XMIN}}$.
4:     A(LA) – REAL (KIND=nag_wp) arrayInput
On entry: the Chebyshev coefficients of the polynomial $p\left(x\right)$. Specifically, element $\mathit{i}×{\mathbf{IA1}}+1$ of A must contain the coefficient ${a}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$. Only these $n+1$ elements will be accessed.
Unchanged on exit, but see AINTC, below.
5:     IA1 – INTEGERInput
On entry: the index increment of A. Most frequently the Chebyshev coefficients are stored in adjacent elements of A, and IA1 must be set to $1$. However, if for example, they are stored in ${\mathbf{A}}\left(1\right),{\mathbf{A}}\left(4\right),{\mathbf{A}}\left(7\right),\dots \text{}$, then the value of IA1 must be $3$. See also Section 8.
Constraint: ${\mathbf{IA1}}\ge 1$.
6:     LA – INTEGERInput
On entry: the dimension of the array A as declared in the (sub)program from which E02AJF is called.
Constraint: ${\mathbf{LA}}\ge 1+\left({\mathbf{NP1}}-1\right)×{\mathbf{IA1}}$.
7:     QATM1 – REAL (KIND=nag_wp)Input
On entry: the value that the integrated polynomial is required to have at the lower end point of its interval of definition, i.e., at $\stackrel{-}{x}=-1$ which corresponds to $x={x}_{\mathrm{min}}$. Thus, QATM1 is a constant of integration and will normally be set to zero by you.
8:     AINTC(LAINT) – REAL (KIND=nag_wp) arrayOutput
On exit: the Chebyshev coefficients of the integral $q\left(x\right)$. (The integration is with respect to the variable $x$, and the constant coefficient is chosen so that $q\left({x}_{\mathrm{min}}\right)$ equals QATM1). Specifically, element $i×{\mathbf{IAINT1}}+1$ of AINTC contains the coefficient ${a}_{\mathit{i}}^{\prime }$, for $\mathit{i}=0,1,\dots ,n+1$. A call of the routine may have the array name AINTC the same as A, provided that note is taken of the order in which elements are overwritten when choosing starting elements and increments IA1 and IAINT1: i.e., the coefficients, ${a}_{0},{a}_{1},\dots ,{a}_{i-2}$ must be intact after coefficient ${a}_{i}^{\prime }$ is stored. In particular it is possible to overwrite the ${a}_{i}$ entirely by having ${\mathbf{IA1}}={\mathbf{IAINT1}}$, and the actual array for A and AINTC identical.
9:     IAINT1 – INTEGERInput
On entry: the index increment of AINTC. Most frequently the Chebyshev coefficients are required in adjacent elements of AINTC, and IAINT1 must be set to $1$. However, if, for example, they are to be stored in ${\mathbf{AINTC}}\left(1\right),{\mathbf{AINTC}}\left(4\right),{\mathbf{AINTC}}\left(7\right),\dots \text{}$, then the value of IAINT1 must be $3$. See also Section 8.
Constraint: ${\mathbf{IAINT1}}\ge 1$.
10:   LAINT – INTEGERInput
On entry: the dimension of the array AINTC as declared in the (sub)program from which E02AJF is called.
Constraint: ${\mathbf{LAINT}}\ge 1+\left({\mathbf{NP1}}\right)×{\mathbf{IAINT1}}$.
11:   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{NP1}}<1$, or ${\mathbf{XMAX}}\le {\mathbf{XMIN}}$, or ${\mathbf{IA1}}<1$, or ${\mathbf{LA}}\le \left({\mathbf{NP1}}-1\right)×{\mathbf{IA1}}$, or ${\mathbf{IAINT1}}<1$, or ${\mathbf{LAINT}}\le {\mathbf{NP1}}×{\mathbf{IAINT1}}$.

## 7  Accuracy

In general there is a gain in precision in numerical integration, in this case associated with the division by $2i$ in the formula quoted in Section 3.

The time taken is approximately proportional to $n+1$.
The increments IA1, IAINT1 are included as parameters to give a degree of flexibility which, for example, allows a polynomial in two variables to be integrated with respect to either variable without rearranging the coefficients.

## 9  Example

Suppose a polynomial has been computed in Chebyshev series form to fit data over the interval $\left[-0.5,2.5\right]$. The following program evaluates the integral of the polynomial from $0.0$ to $2.0$. (For the purpose of this example, XMIN, XMAX and the Chebyshev coefficients are simply supplied in DATA statements. Normally a program would read in or generate data and compute the fitted polynomial).

### 9.1  Program Text

Program Text (e02ajfe.f90)

None.

### 9.3  Program Results

Program Results (e02ajfe.r)