# NAG FL Interfacee02cbf (dim2_​cheb_​eval)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e02cbf ( k, l, x, xmin, xmax, y, ymin, ymax, ff, a, na, work,
 Integer, Intent (In) :: mfirst, mlast, k, l, na, nwork Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(mlast), xmin, xmax, y, ymin, ymax, a(na) Real (Kind=nag_wp), Intent (Out) :: ff(mlast), work(nwork)
#include <nag.h>
 void e02cbf_ (const Integer *mfirst, const Integer *mlast, const Integer *k, const Integer *l, const double x[], const double *xmin, const double *xmax, const double *y, const double *ymin, const double *ymax, double ff[], const double a[], const Integer *na, double work[], const Integer *nwork, Integer *ifail)
The routine may be called by the names e02cbf or nagf_fit_dim2_cheb_eval.

## 3Description

This subroutine evaluates a bivariate polynomial (represented in double Chebyshev form) of degree $k$ in one variable, $\overline{x}$, and degree $l$ in the other, $\overline{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 $\overline{x}$. ${y}_{\mathrm{min}}$ and ${y}_{\mathrm{max}}$ are correspondingly for $y$. See Section 9). For this reason, the subroutine has been designed to accept values of $x$ and $y$ rather than $\overline{x}$ and $\overline{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=0laijTi(x¯)Tj(y¯),$
where ${T}_{i}\left(\overline{x}\right)$ is the Chebyshev polynomial of the first kind of degree $i$ and argument $\overline{x}$, and ${T}_{j}\left(\overline{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(\overline{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(\overline{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.
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

## 5Arguments

1: $\mathbf{mfirst}$Integer Input
2: $\mathbf{mlast}$Integer Input
On entry: the index of the first and last $x$ value in the array $x$ at which the evaluation is required respectively (see Section 9).
Constraint: ${\mathbf{mlast}}\ge {\mathbf{mfirst}}$.
3: $\mathbf{k}$Integer Input
4: $\mathbf{l}$Integer Input
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: $\mathbf{x}\left({\mathbf{mlast}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{xmin}$Real (Kind=nag_wp) Input
7: $\mathbf{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: $\mathbf{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: $\mathbf{ymin}$Real (Kind=nag_wp) Input
10: $\mathbf{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: $\mathbf{ff}\left({\mathbf{mlast}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{a}\left({\mathbf{na}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{na}$Integer Input
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: $\mathbf{work}\left({\mathbf{nwork}}\right)$Real (Kind=nag_wp) array Workspace
15: $\mathbf{nwork}$Integer Input
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: $\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{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{k}}\ge 0$.
On entry, ${\mathbf{l}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{l}}\ge 0$.
On entry, ${\mathbf{mfirst}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{mlast}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{mfirst}}\le {\mathbf{mlast}}$.
On entry, ${\mathbf{na}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{l}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{na}}\ge \left({\mathbf{k}}+1\right)×\left({\mathbf{l}}+1\right)$.
On entry, ${\mathbf{nwork}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nwork}}\ge {\mathbf{k}}+1$.
${\mathbf{ifail}}=2$
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}}$.
${\mathbf{ifail}}=3$
On entry, $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{x}}\left(\mathit{I}\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{xmax}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{x}}\left(\mathit{I}\right)\le {\mathbf{xmax}}$.
On entry, $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{x}}\left(\mathit{I}\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{xmin}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{x}}\left(\mathit{I}\right)\ge {\mathbf{xmin}}$.
On entry, ${\mathbf{xmin}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{xmax}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{xmin}}<{\mathbf{xmax}}$.
${\mathbf{ifail}}=4$
Unexpected internal failure when evaluating the polynomial.
${\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

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.

## 8Parallelism and Performance

e02cbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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 9 in e02caf).
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 e02caf 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 routine are set respectively (in terms of arguments 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).

## 10Example

This example reads data in the following order, using the notation of the argument list above:
 $N k l a(i), for ​i=1,2,…,(k+1)×(l+1) ymin ymax y(i) M(i) xmin(i) xmax(i) X1(i) XM(i), 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.

### 10.1Program Text

Program Text (e02cbfe.f90)

### 10.2Program Data

Program Data (e02cbfe.d)

### 10.3Program Results

Program Results (e02cbfe.r)