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

# NAG Toolbox: nag_fit_1dcheb_integ (e02aj)

## Purpose

nag_fit_1dcheb_integ (e02aj) determines the coefficients in the Chebyshev series representation of the indefinite integral of a polynomial given in Chebyshev series form.

## Syntax

[aintc, ifail] = e02aj(n, xmin, xmax, a, ia1, qatm1, iaint1)
[aintc, ifail] = nag_fit_1dcheb_integ(n, xmin, xmax, a, ia1, qatm1, iaint1)

## Description

nag_fit_1dcheb_integ (e02aj) 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 ai${a}_{i}$, for i = 0,1,,n$\mathit{i}=0,1,\dots ,n$, of a polynomial p(x)$p\left(x\right)$ of degree n$n$, where
 p(x) = (1/2)a0 + a1T1(x) + ⋯ + anTn(x), $p(x)=12a0+a1T1(x-)+⋯+anTn(x-),$
the function returns the coefficients ai${a}_{i}^{\prime }$, for i = 0,1,,n + 1$\mathit{i}=0,1,\dots ,n+1$, of the polynomial q(x)$q\left(x\right)$ of degree n + 1$n+1$, where
 q(x) = (1/2)a0 ′ + a1 ′ T1(x) + ⋯ + an + 1 ′ Tn + 1(x), $q(x)=12a0′+a1′T1(x-)+⋯+an+1′Tn+1(x-),$
and
 q(x) = ∫ p(x)dx. $q(x)=∫p(x)dx.$
Here Tj(x)${T}_{j}\left(\stackrel{-}{x}\right)$ denotes the Chebyshev polynomial of the first kind of degree j$j$ with argument x$\stackrel{-}{x}$. It is assumed that the normalized variable x$\stackrel{-}{x}$ in the interval [1, + 1]$\left[-1,+1\right]$ was obtained from your original variable x$x$ in the interval [xmin,xmax]$\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$ by the linear transformation
 x = (2x − (xmax + xmin))/(xmax − xmin) $x-=2x-(xmax+xmin) xmax-xmin$
and that you require the integral to be with respect to the variable x$x$. If the integral with respect to x$\stackrel{-}{x}$ is required, set xmax = 1${x}_{\mathrm{max}}=1$ and xmin = 1${x}_{\mathrm{min}}=-1$.
Values of the integral can subsequently be computed, from the coefficients obtained, by using nag_fit_1dcheb_eval2 (e02ak).
The method employed is that of Chebyshev series (see Chapter 8 of Modern Computing Methods (1961)), modified for integrating with respect to x$x$. Initially taking an + 1 = an + 2 = 0${a}_{n+1}={a}_{n+2}=0$, the function forms successively
 ai ′ = (ai − 1 − ai + 1)/(2i) × (xmax − xmin)/2,  i = n + 1,n, … ,1. $ai′=ai-1-ai+1 2i ×xmax-xmin2, i=n+1,n,…,1.$
The constant coefficient a0${a}_{0}^{\prime }$ is chosen so that q(x)$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., x = 1$\stackrel{-}{x}=-1$, which corresponds to x = xmin$x={x}_{\mathrm{min}}$.

## References

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

## Parameters

### Compulsory Input Parameters

1:     n – int64int32nag_int scalar
n$n$, the degree of the given polynomial p(x)$p\left(x\right)$.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     xmin – double scalar
3:     xmax – double scalar
The lower and upper end points respectively of the interval [xmin,xmax]$\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]$. The Chebyshev series representation is in terms of the normalized variable x$\stackrel{-}{x}$, where
 x = (2x − (xmax + xmin))/(xmax − xmin). $x-=2x-(xmax+xmin) xmax-xmin .$
Constraint: ${\mathbf{xmax}}>{\mathbf{xmin}}$.
4:     a(la) – double array
la, the dimension of the array, must satisfy the constraint la1 + (np11) × ia1$\mathit{la}\ge 1+\left(\mathit{np1}-1\right)×{\mathbf{ia1}}$.
The Chebyshev coefficients of the polynomial p(x)$p\left(x\right)$. Specifically, element i × ia1 + 1$\mathit{i}×{\mathbf{ia1}}+1$ of a must contain the coefficient ai${a}_{\mathit{i}}$, for i = 0,1,,n$\mathit{i}=0,1,\dots ,n$. Only these n + 1$n+1$ elements will be accessed.
Unchanged on exit, but see aintc, below.
5:     ia1 – int64int32nag_int scalar
The index increment of a. Most frequently the Chebyshev coefficients are stored in adjacent elements of a, and ia1 must be set to 1$1$. However, if for example, they are stored in a(1),a(4),a(7),${\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$3$. See also Section [Further Comments].
Constraint: ia11${\mathbf{ia1}}\ge 1$.
6:     qatm1 – double scalar
The value that the integrated polynomial is required to have at the lower end point of its interval of definition, i.e., at x = 1$\stackrel{-}{x}=-1$ which corresponds to x = xmin$x={x}_{\mathrm{min}}$. Thus, qatm1 is a constant of integration and will normally be set to zero by you.
7:     iaint1 – int64int32nag_int scalar
The index increment of aintc. Most frequently the Chebyshev coefficients are required in adjacent elements of aintc, and iaint1 must be set to 1$1$. However, if, for example, they are to be stored in aintc(1),aintc(4),aintc(7),${\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$3$. See also Section [Further Comments].
Constraint: iaint11${\mathbf{iaint1}}\ge 1$.

None.

np1 la laint

### Output Parameters

1:     aintc(laint) – double array
laint1 + (np1) × iaint1$\mathit{laint}\ge 1+\left(\mathit{np1}\right)×{\mathbf{iaint1}}$.
The Chebyshev coefficients of the integral q(x)$q\left(x\right)$. (The integration is with respect to the variable x$x$, and the constant coefficient is chosen so that q(xmin)$q\left({x}_{\mathrm{min}}\right)$ equals qatm1). Specifically, element i × iaint1 + 1$i×{\mathbf{iaint1}}+1$ of aintc contains the coefficient ai${a}_{\mathit{i}}^{\prime }$, for i = 0,1,,n + 1$\mathit{i}=0,1,\dots ,n+1$. A call of the function 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, a0,a1,,ai2${a}_{0},{a}_{1},\dots ,{a}_{i-2}$ must be intact after coefficient ai${a}_{i}^{\prime }$ is stored. In particular it is possible to overwrite the ai${a}_{i}$ entirely by having ${\mathbf{ia1}}={\mathbf{iaint1}}$, and the actual array for a and aintc identical.
2:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, np1 < 1$\mathit{np1}<1$, or ${\mathbf{xmax}}\le {\mathbf{xmin}}$, or ia1 < 1${\mathbf{ia1}}<1$, or la ≤ (np1 − 1) × ia1$\mathit{la}\le \left(\mathit{np1}-1\right)×{\mathbf{ia1}}$, or iaint1 < 1${\mathbf{iaint1}}<1$, or laint ≤ np1 × iaint1$\mathit{laint}\le \mathit{np1}×{\mathbf{iaint1}}$.

## Accuracy

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

The time taken is approximately proportional to n + 1$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.

## Example

```function nag_fit_1dcheb_integ_example
n = int64(6);
xmin = -0.5;
xmax = 2.5;
a = [2.53213;
1.13032;
0.2715;
0.04434;
0.00547;
0.00054;
4e-05];
ia1 = int64(1);
qatm1 = 0;
iaint1 = int64(1);
[aint, ifail] = nag_fit_1dcheb_integ(n, xmin, xmax, a, ia1, qatm1, iaint1)
```
```

aint =

2.6946
1.6955
0.4072
0.0665
0.0082
0.0008
0.0001
0.0000

ifail =

0

```
```function e02aj_example
n = int64(6);
xmin = -0.5;
xmax = 2.5;
a = [2.53213;
1.13032;
0.2715;
0.04434;
0.00547;
0.00054;
4e-05];
ia1 = int64(1);
qatm1 = 0;
iaint1 = int64(1);
[aint, ifail] = e02aj(n, xmin, xmax, a, ia1, qatm1, iaint1)
```
```

aint =

2.6946
1.6955
0.4072
0.0665
0.0082
0.0008
0.0001
0.0000

ifail =

0

```