e02 Chapter Contents
e02 Chapter Introduction
NAG Library Manual

NAG Library Function Documentnag_1d_cheb_intg (e02ajc)

1  Purpose

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

2  Specification

 #include #include
 void nag_1d_cheb_intg (Integer n, double xmin, double xmax, const double a[], Integer ia1, double qatm1, double aintc[], Integer iaint1, NagError *fail)

3  Description

nag_1d_cheb_intg (e02ajc) 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 function 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 nag_1d_cheb_eval2 (e02akc).
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 function 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  Arguments

1:    $\mathbf{n}$IntegerInput
On entry: $n$, the degree of the given polynomial $p\left(x\right)$.
Constraint: ${\mathbf{n}}\ge 0$.
2:    $\mathbf{xmin}$doubleInput
3:    $\mathbf{xmax}$doubleInput
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:    $\mathbf{a}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array a must be at least $\left(1+\left({\mathbf{n}}+1-1\right)×{\mathbf{ia1}}\right)$.
On entry: the Chebyshev coefficients of the polynomial $p\left(x\right)$. Specifically, element $\mathit{i}×{\mathbf{ia1}}$ of a must contain the coefficient ${a}_{\mathit{i}}$, for $\mathit{i}=0,1,\dots ,n$. Only these $n+1$ elements will be accessed.
5:    $\mathbf{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[0\right],{\mathbf{a}}\left[3\right],{\mathbf{a}}\left[6\right],\dots \text{}$, then the value of ia1 must be $3$. See also Section 9.
Constraint: ${\mathbf{ia1}}\ge 1$.
6:    $\mathbf{qatm1}$doubleInput
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.
7:    $\mathbf{aintc}\left[\mathit{dim}\right]$doubleOutput
Note: the dimension, dim, of the array aintc must be at least $\left(1+\left({\mathbf{n}}+1\right)×{\mathbf{iaint1}}\right)$.
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}}$ of aintc contains the coefficient ${a}_{\mathit{i}}^{\prime }$, for $\mathit{i}=0,1,\dots ,n+1$.
8:    $\mathbf{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[0\right],{\mathbf{aintc}}\left[3\right],{\mathbf{aintc}}\left[6\right],\dots \text{}$, then the value of iaint1 must be $3$. See also Section 9.
Constraint: ${\mathbf{iaint1}}\ge 1$.
9:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.2.1.2 in the Essential Introduction for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
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{n}}+1=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}+1\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 3.6.6 in the Essential Introduction for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction for further information.
NE_REAL_2
On entry, ${\mathbf{xmax}}=〈\mathit{\text{value}}〉$ and ${\mathbf{xmin}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{xmax}}>{\mathbf{xmin}}$.

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.

8  Parallelism and Performance

Not applicable.

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.

10  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 . Normally a program would read in or generate data and compute the fitted polynomial).

10.1  Program Text

Program Text (e02ajce.c)

None.

10.3  Program Results

Program Results (e02ajce.r)