e02 Chapter Contents
e02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_2d_cheb_eval (e02cbc)

## 1  Purpose

nag_2d_cheb_eval (e02cbc) evaluates a bivariate polynomial from the rectangular array of coefficients in its double Chebyshev series representation.

## 2  Specification

 #include #include
 void nag_2d_cheb_eval (Integer mfirst, Integer mlast, Integer k, Integer l, const double x[], double xmin, double xmax, double y, double ymin, double ymax, double ff[], const double a[], NagError *fail)

## 3  Description

This function 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 nag_2d_cheb_fit_lines (e02cac), 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 function 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 function 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 function, 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 function 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  Arguments

1:     mfirstIntegerInput
2:     mlastIntegerInput
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:     kIntegerInput
4:     lIntegerInput
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]const doubleInput
On entry: ${\mathbf{x}}\left[\mathit{i}-1\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-1\right]\le {\mathbf{xmax}}$, for all $i$.
6:     xmindoubleInput
7:     xmaxdoubleInput
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 nag_2d_cheb_fit_lines (e02cac)).
Constraint: ${\mathbf{xmax}}>{\mathbf{xmin}}$.
8:     ydoubleInput
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:     ymindoubleInput
10:   ymaxdoubleInput
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]doubleOutput
On exit: ${\mathbf{ff}}\left[\mathit{i}-1\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[$\mathit{dim}$]const doubleInput
Note: the dimension, dim, of the array a must be at least $\left(\left({\mathbf{k}}+1\right)×\left({\mathbf{l}}+1\right)\right)$.
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\right]$.
13:   failNagError *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.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{k}}\ge 0$.
On entry, ${\mathbf{l}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{l}}\ge 0$.
NE_INT_2
On entry, ${\mathbf{k}}=〈\mathit{\text{value}}〉$ and ${\mathbf{l}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{k}}\ge 0$ and ${\mathbf{l}}\ge 0$.
On entry, ${\mathbf{mfirst}}=〈\mathit{\text{value}}〉$ and ${\mathbf{mlast}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mfirst}}\le {\mathbf{mlast}}$.
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.
Unexpected failure in internal call to nag_1d_cheb_eval (e02aec).
NE_REAL_2
On entry, ${\mathbf{xmin}}=〈\mathit{\text{value}}〉$ and ${\mathbf{xmax}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
On entry, ${\mathbf{y}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ymax}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{y}}\le {\mathbf{ymax}}$.
On entry, ${\mathbf{y}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ymin}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{y}}\ge {\mathbf{ymin}}$.
On entry, ${\mathbf{ymin}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ymax}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ymin}}<{\mathbf{ymax}}$.
NE_REAL_ARRAY
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[i-1\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{xmax}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\left[i-1\right]\le {\mathbf{xmax}}$.
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[i-1\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{xmin}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\left[i-1\right]\ge {\mathbf{xmin}}$.

## 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 function is suitable for evaluating the polynomial surface fits produced by the function nag_2d_cheb_fit_lines (e02cac), which provides the array a in the required form. For this use, the values of ${y}_{\mathrm{min}}$ and ${y}_{\mathrm{max}}$ supplied to the present function must be the same as those supplied to nag_2d_cheb_fit_lines (e02cac). 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 nag_2d_cheb_fit_lines (e02cac) (see Section 8 in nag_2d_cheb_fit_lines (e02cac)).
The arguments 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 nag_2d_cheb_fit_lines (e02cac) to fit a set of data, you wish to evaluate the resulting polynomial at all the data values. In this case, if the arguments x, y, mfirst and mlast of the present function are set respectively (in terms of arguments of nag_2d_cheb_fit_lines (e02cac)) 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 function will compute values of the polynomial surface at all data points which have ${\mathbf{y}}\left[S-1\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 argument list above:
 $N k l a[i-1], for ​i=1,2,…,k+1×l+1 ymin ymax y[i-1] Mi-1 xmin[i-1] xmax[i-1] X1i XMi, for ​i=1,2,…,N.$
For each line ${\mathbf{y}}={\mathbf{y}}\left[i-1\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 (e02cbce.c)

### 9.2  Program Data

Program Data (e02cbce.d)

### 9.3  Program Results

Program Results (e02cbce.r)