# NAG FL Interfacee02ajf (dim1_​cheb_​integ)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e02ajf ( np1, xmin, xmax, a, ia1, la,
 Integer, Intent (In) :: np1, ia1, la, iaint1, laint Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: xmin, xmax, a(la), qatm1 Real (Kind=nag_wp), Intent (Out) :: aintc(laint)
#include <nag.h>
 void e02ajf_ (const Integer *np1, const double *xmin, const double *xmax, const double a[], const Integer *ia1, const Integer *la, const double *qatm1, double aintc[], const Integer *iaint1, const Integer *laint, Integer *ifail)
The routine may be called by the names e02ajf or nagf_fit_dim1_cheb_integ.

## 3Description

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
 $p(x)=12a0+a1T1(x¯)+⋯+anTn(x¯),$
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
 $q(x)=12a0′+a1′T1(x¯)+⋯+an+1′Tn+1(x¯),$
and
 $q(x)=∫p(x)dx.$
Here ${T}_{j}\left(\overline{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree $j$ with argument $\overline{x}$. It is assumed that the normalized variable $\overline{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 $\overline{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., $\overline{x}=-1$, which corresponds to $x={x}_{\mathrm{min}}$.

## 4References

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

## 5Arguments

1: $\mathbf{np1}$Integer Input
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: $\mathbf{xmin}$Real (Kind=nag_wp) Input
3: $\mathbf{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 $\overline{x}$, where
 $x¯=2x-(xmax+xmin) xmax-xmin .$
Constraint: ${\mathbf{xmax}}>{\mathbf{xmin}}$.
4: $\mathbf{a}\left({\mathbf{la}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{ia1}$Integer Input
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{}$, the value of ia1 must be $3$. See also Section 9.
Constraint: ${\mathbf{ia1}}\ge 1$.
6: $\mathbf{la}$Integer Input
On entry: the dimension of the array a as declared in the (sub)program from which e02ajf is called.
Constraints:
• ${\mathbf{la}}\ge 1+\left({\mathbf{np1}}-1\right)×{\mathbf{ia1}}$.
7: $\mathbf{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 $\overline{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: $\mathbf{aintc}\left({\mathbf{laint}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{iaint1}$Integer Input
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{}$, the value of iaint1 must be $3$. See also Section 9.
Constraint: ${\mathbf{iaint1}}\ge 1$.
10: $\mathbf{laint}$Integer Input
On entry: the dimension of the array aintc as declared in the (sub)program from which e02ajf is called.
Constraints:
• ${\mathbf{laint}}\ge 1+\left({\mathbf{np1}}\right)×{\mathbf{iaint1}}$.
11: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error 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{ia1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ia1}}\ge 1$.
On entry, ${\mathbf{iaint1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{iaint1}}\ge 1$.
On entry, ${\mathbf{la}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{np1}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ia1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{la}}>\left({\mathbf{np1}}-1\right)×{\mathbf{ia1}}$.
On entry, ${\mathbf{laint}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{np1}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{iaint1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{laint}}>{\mathbf{np1}}×{\mathbf{iaint1}}$.
On entry, ${\mathbf{np1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{np1}}\ge 1$.
On entry, ${\mathbf{xmax}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{xmin}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{xmax}}>{\mathbf{xmin}}$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

e02ajf is not threaded in any implementation.

The time taken is approximately proportional to $n+1$.
The increments ia1, iaint1 are included as arguments 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.

## 10Example

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).

### 10.1Program Text

Program Text (e02ajfe.f90)

None.

### 10.3Program Results

Program Results (e02ajfe.r)