E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02CBF

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

E02CBF evaluates a bivariate polynomial from the rectangular array of coefficients in its double Chebyshev series representation.

## 2  Specification

 SUBROUTINE E02CBF ( MFIRST, MLAST, K, L, X, XMIN, XMAX, Y, YMIN, YMAX, FF, A, NA, WORK, NWORK, IFAIL)
 INTEGER MFIRST, MLAST, K, L, NA, NWORK, IFAIL REAL (KIND=nag_wp) X(MLAST), XMIN, XMAX, Y, YMIN, YMAX, FF(MLAST), A(NA), WORK(NWORK)

## 3  Description

This subroutine evaluates a bivariate polynomial (represented in double Chebyshev form) of degree $k$ in one variable, $\stackrel{-}{x}$, and degree $l$ in the other, $\stackrel{-}{y}$. The range of both variables is $-1$ to $+1$. However, these normalized variables will usually have been derived (as when the polynomial has been computed by E02CAF, for example) from your original variables $x$ and $y$ by the transformations
 $x-=2x-xmax+xmin xmax-xmin and y-=2y-ymax+ymin ymax-ymin .$
(Here ${x}_{\mathrm{min}}$ and ${x}_{\mathrm{max}}$ are the ends of the range of $x$ which has been transformed to the range $-1$ to $+1$ of $\stackrel{-}{x}$. ${y}_{\mathrm{min}}$ and ${y}_{\mathrm{max}}$ are correspondingly for $y$. See Section 8). For this reason, the subroutine has been designed to accept values of $x$ and $y$ rather than $\stackrel{-}{x}$ and $\stackrel{-}{y}$, and so requires values of ${x}_{\mathrm{min}}$, etc. to be supplied by you. In fact, for the sake of efficiency in appropriate cases, the routine evaluates the polynomial for a sequence of values of $x$, all associated with the same value of $y$.
The double Chebyshev series can be written as
 $∑i=0k∑j=0laijTix-Tjy-,$
where ${T}_{i}\left(\stackrel{-}{x}\right)$ is the Chebyshev polynomial of the first kind of degree $i$ and argument $\stackrel{-}{x}$, and ${T}_{j}\left(\stackrel{-}{y}\right)$ is similarly defined. However the standard convention, followed in this subroutine, is that coefficients in the above expression which have either $i$ or $j$ zero are written $\frac{1}{2}{a}_{ij}$, instead of simply ${a}_{ij}$, and the coefficient with both $i$ and $j$ zero is written $\frac{1}{4}{a}_{0,0}$.
The subroutine first forms ${c}_{i}=\sum _{j=0}^{l}{a}_{ij}{T}_{j}\left(\stackrel{-}{y}\right)$, with ${a}_{i,0}$ replaced by $\frac{1}{2}{a}_{i,0}$, for each of $i=0,1,\dots ,k$. The value of the double series is then obtained for each value of $x$, by summing ${c}_{i}×{T}_{i}\left(\stackrel{-}{x}\right)$, with ${c}_{0}$ replaced by $\frac{1}{2}{c}_{0}$, over $i=0,1,\dots ,k$. The Clenshaw three term recurrence (see Clenshaw (1955)) with modifications due to Reinsch and Gentleman (1969) is used to form the sums.

## 4  References

Clenshaw C W (1955) A note on the summation of Chebyshev series Math. Tables Aids Comput. 9 118–120
Gentleman W M (1969) An error analysis of Goertzel's (Watt's) method for computing Fourier coefficients Comput. J. 12 160–165

## 5  Parameters

1:     MFIRST – INTEGERInput
2:     MLAST – INTEGERInput
On entry: the index of the first and last $x$ value in the array $x$ at which the evaluation is required respectively (see Section 8).
Constraint: ${\mathbf{MLAST}}\ge {\mathbf{MFIRST}}$.
3:     K – INTEGERInput
4:     L – INTEGERInput
On entry: the degree $k$ of $x$ and $l$ of $y$, respectively, in the polynomial.
Constraint: ${\mathbf{K}}\ge 0$ and ${\mathbf{L}}\ge 0$.
5:     X(MLAST) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{X}}\left(\mathit{i}\right)$, for $\mathit{i}={\mathbf{MFIRST}},\dots ,{\mathbf{MLAST}}$, must contain the $x$ values at which the evaluation is required.
Constraint: ${\mathbf{XMIN}}\le {\mathbf{X}}\left(i\right)\le {\mathbf{XMAX}}$, for all $i$.
6:     XMIN – REAL (KIND=nag_wp)Input
7:     XMAX – REAL (KIND=nag_wp)Input
On entry: the lower and upper ends, ${x}_{\mathrm{min}}$ and ${x}_{\mathrm{max}}$, of the range of the variable $x$ (see Section 3).
The values of XMIN and XMAX may depend on the value of $y$ (e.g., when the polynomial has been derived using E02CAF).
Constraint: ${\mathbf{XMAX}}>{\mathbf{XMIN}}$.
8:     Y – REAL (KIND=nag_wp)Input
On entry: the value of the $y$ coordinate of all the points at which the evaluation is required.
Constraint: ${\mathbf{YMIN}}\le {\mathbf{Y}}\le {\mathbf{YMAX}}$.
9:     YMIN – REAL (KIND=nag_wp)Input
10:   YMAX – REAL (KIND=nag_wp)Input
On entry: the lower and upper ends, ${y}_{\mathrm{min}}$ and ${y}_{\mathrm{max}}$, of the range of the variable $y$ (see Section 3).
Constraint: ${\mathbf{YMAX}}>{\mathbf{YMIN}}$.
11:   FF(MLAST) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{FF}}\left(\mathit{i}\right)$ gives the value of the polynomial at the point $\left({x}_{\mathit{i}},y\right)$, for $\mathit{i}={\mathbf{MFIRST}},\dots ,{\mathbf{MLAST}}$.
12:   A(NA) – REAL (KIND=nag_wp) arrayInput
On entry: the Chebyshev coefficients of the polynomial. The coefficient ${a}_{ij}$ defined according to the standard convention (see Section 3) must be in ${\mathbf{A}}\left(i×\left(l+1\right)+j+1\right)$.
13:   NA – INTEGERInput
On entry: the dimension of the array A as declared in the (sub)program from which E02CBF is called.
Constraint: ${\mathbf{NA}}\ge \left({\mathbf{K}}+1\right)×\left({\mathbf{L}}+1\right)$, the number of coefficients in a polynomial of the specified degree.
14:   WORK(NWORK) – REAL (KIND=nag_wp) arrayWorkspace
15:   NWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which E02CBF is called.
Constraint: ${\mathbf{NWORK}}\ge {\mathbf{K}}+1$.
16:   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{MFIRST}}>{\mathbf{MLAST}}$, or ${\mathbf{K}}<0$, or ${\mathbf{L}}<0$, or ${\mathbf{NA}}<\left({\mathbf{K}}+1\right)×\left({\mathbf{L}}+1\right)$, or ${\mathbf{NWORK}}<{\mathbf{K}}+1$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{YMIN}}\ge {\mathbf{YMAX}}$, or ${\mathbf{Y}}<{\mathbf{YMIN}}$, or ${\mathbf{Y}}>{\mathbf{YMAX}}$.
${\mathbf{IFAIL}}=3$
 On entry, ${\mathbf{XMIN}}\ge {\mathbf{XMAX}}$, or ${\mathbf{X}}\left(i\right)<{\mathbf{XMIN}}$, or ${\mathbf{X}}\left(i\right)>{\mathbf{XMAX}}$, for some $i={\mathbf{MFIRST}},{\mathbf{MFIRST}}+1,\dots ,{\mathbf{MLAST}}$.

## 7  Accuracy

The method is numerically stable in the sense that the computed values of the polynomial are exact for a set of coefficients which differ from those supplied by only a modest multiple of machine precision.

The time taken is approximately proportional to $\left(k+1\right)×\left(m+l+1\right)$, where $m={\mathbf{MLAST}}-{\mathbf{MFIRST}}+1$, the number of points at which the evaluation is required.
This subroutine is suitable for evaluating the polynomial surface fits produced by the subroutine E02CAF, which provides the real array A in the required form. For this use, the values of ${y}_{\mathrm{min}}$ and ${y}_{\mathrm{max}}$ supplied to the present subroutine must be the same as those supplied to E02CAF. The same applies to ${x}_{\mathrm{min}}$ and ${x}_{\mathrm{max}}$ if they are independent of $y$. If they vary with $y$, their values must be consistent with those supplied to E02CAF (see Section 8 in E02CAF).
The parameters MFIRST and MLAST are intended to permit the selection of a segment of the array X which is to be associated with a particular value of $y$, when, for example, other segments of X are associated with other values of $y$. Such a case arises when, after using E02CAF to fit a set of data, you wish to evaluate the resulting polynomial at all the data values. In this case, if the parameters X, Y, MFIRST and MLAST of the present routine are set respectively (in terms of parameters of E02CAF) to X, ${\mathbf{Y}}\left(S\right)$, $1+\sum _{i=1}^{s-1}{\mathbf{M}}\left(i\right)$ and $\sum _{i=1}^{s}{\mathbf{M}}\left(i\right)$, the routine will compute values of the polynomial surface at all data points which have ${\mathbf{Y}}\left(S\right)$ as their $y$ coordinate (from which values the residuals of the fit may be derived).

## 9  Example

This example reads data in the following order, using the notation of the parameter list above:
 $N K L Ai, for ​i=1,2,…,K+1×L+1 YMIN YMAX Yi Mi XMINi XMAXi X1i XMi, for ​i=1,2,…,N.$
For each line ${\mathbf{Y}}={\mathbf{Y}}\left(i\right)$ the polynomial is evaluated at $M\left(i\right)$ equispaced points between $\mathrm{X1}\left(i\right)$ and $\mathrm{XM}\left(i\right)$ inclusive.

### 9.1  Program Text

Program Text (e02cbfe.f90)

### 9.2  Program Data

Program Data (e02cbfe.d)

### 9.3  Program Results

Program Results (e02cbfe.r)