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_2dcheb_eval (e02cb)

## Purpose

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

## Syntax

[ff, ifail] = e02cb(mfirst, k, l, x, xmin, xmax, y, ymin, ymax, a, 'mlast', mlast)
[ff, ifail] = nag_fit_2dcheb_eval(mfirst, k, l, x, xmin, xmax, y, ymin, ymax, a, 'mlast', mlast)

## Description

This function evaluates a bivariate polynomial (represented in double Chebyshev form) of degree k$k$ in one variable, x$\stackrel{-}{x}$, and degree l$l$ in the other, y$\stackrel{-}{y}$. The range of both variables is 1$-1$ to + 1$+1$. However, these normalized variables will usually have been derived (as when the polynomial has been computed by nag_fit_2dcheb_lines (e02ca), for example) from your original variables x$x$ and y$y$ by the transformations
 x = (2x − (xmax + xmin))/((xmax − xmin))  and  y = (2y − (ymax + ymin))/((ymax − ymin)). $x-=2x-(xmax+xmin) (xmax-xmin) and y-=2y-(ymax+ymin) (ymax-ymin) .$
(Here xmin${x}_{\mathrm{min}}$ and xmax${x}_{\mathrm{max}}$ are the ends of the range of x$x$ which has been transformed to the range 1$-1$ to + 1$+1$ of x$\stackrel{-}{x}$. ymin${y}_{\mathrm{min}}$ and ymax${y}_{\mathrm{max}}$ are correspondingly for y$y$. See Section [Further Comments]). For this reason, the function has been designed to accept values of x$x$ and y$y$ rather than x$\stackrel{-}{x}$ and y$\stackrel{-}{y}$, and so requires values of xmin${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$x$, all associated with the same value of y$y$.
The double Chebyshev series can be written as
 k l ∑ ∑ aijTi(x)Tj(y), i = 0 j = 0
$∑i=0k∑j=0laijTi(x-)Tj(y-),$
where Ti(x)${T}_{i}\left(\stackrel{-}{x}\right)$ is the Chebyshev polynomial of the first kind of degree i$i$ and argument x$\stackrel{-}{x}$, and Tj(y)${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$i$ or j$j$ zero are written (1/2)aij$\frac{1}{2}{a}_{ij}$, instead of simply aij${a}_{ij}$, and the coefficient with both i$i$ and j$j$ zero is written (1/4)a0,0$\frac{1}{4}{a}_{0,0}$.
The function first forms ci = j = 0laijTj(y)${c}_{i}=\sum _{j=0}^{l}{a}_{ij}{T}_{j}\left(\stackrel{-}{y}\right)$, with ai,0${a}_{i,0}$ replaced by (1/2)ai,0$\frac{1}{2}{a}_{i,0}$, for each of i = 0,1,,k$i=0,1,\dots ,k$. The value of the double series is then obtained for each value of x$x$, by summing ci × Ti(x)${c}_{i}×{T}_{i}\left(\stackrel{-}{x}\right)$, with c0${c}_{0}$ replaced by (1/2)c0$\frac{1}{2}{c}_{0}$, over i = 0,1,,k$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.

## 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

## Parameters

### Compulsory Input Parameters

1:     mfirst – int64int32nag_int scalar
The index of the first and last x$x$ value in the array x$x$ at which the evaluation is required respectively (see Section [Further Comments]).
Constraint: ${\mathbf{mlast}}\ge {\mathbf{mfirst}}$.
2:     k – int64int32nag_int scalar
3:     l – int64int32nag_int scalar
The degree k$k$ of x$x$ and l$l$ of y$y$, respectively, in the polynomial.
Constraint: k0${\mathbf{k}}\ge 0$ and l0${\mathbf{l}}\ge 0$.
4:     x(mlast) – double array
mlast, the dimension of the array, must satisfy the constraint ${\mathbf{mlast}}\ge {\mathbf{mfirst}}$.
x(i)${\mathbf{x}}\left(\mathit{i}\right)$, for i = mfirst,,mlast$\mathit{i}={\mathbf{mfirst}},\dots ,{\mathbf{mlast}}$, must contain the x$x$ values at which the evaluation is required.
Constraint: xminx(i)xmax${\mathbf{xmin}}\le {\mathbf{x}}\left(i\right)\le {\mathbf{xmax}}$, for all i$i$.
5:     xmin – double scalar
6:     xmax – double scalar
The lower and upper ends, xmin${x}_{\mathrm{min}}$ and xmax${x}_{\mathrm{max}}$, of the range of the variable x$x$ (see Section [Description]).
The values of xmin and xmax may depend on the value of y$y$ (e.g., when the polynomial has been derived using nag_fit_2dcheb_lines (e02ca)).
Constraint: ${\mathbf{xmax}}>{\mathbf{xmin}}$.
7:     y – double scalar
The value of the y$y$ coordinate of all the points at which the evaluation is required.
Constraint: ${\mathbf{ymin}}\le {\mathbf{y}}\le {\mathbf{ymax}}$.
8:     ymin – double scalar
9:     ymax – double scalar
The lower and upper ends, ymin${y}_{\mathrm{min}}$ and ymax${y}_{\mathrm{max}}$, of the range of the variable y$y$ (see Section [Description]).
Constraint: ${\mathbf{ymax}}>{\mathbf{ymin}}$.
10:   a(na) – double array
na, the dimension of the array, must satisfy the constraint na(k + 1) × (l + 1)$\mathit{na}\ge \left({\mathbf{k}}+1\right)×\left({\mathbf{l}}+1\right)$, the number of coefficients in a polynomial of the specified degree.
The Chebyshev coefficients of the polynomial. The coefficient aij${a}_{ij}$ defined according to the standard convention (see Section [Description]) must be in a(i × (l + 1) + j + 1)${\mathbf{a}}\left(i×\left(l+1\right)+j+1\right)$.

### Optional Input Parameters

1:     mlast – int64int32nag_int scalar
Default: For mlast, the dimension of the array x.
The index of the first and last x$x$ value in the array x$x$ at which the evaluation is required respectively (see Section [Further Comments]).
Constraint: ${\mathbf{mlast}}\ge {\mathbf{mfirst}}$.

na work nwork

### Output Parameters

1:     ff(mlast) – double array
ff(i)${\mathbf{ff}}\left(\mathit{i}\right)$ gives the value of the polynomial at the point (xi,y)$\left({x}_{\mathit{i}},y\right)$, for i = mfirst,,mlast$\mathit{i}={\mathbf{mfirst}},\dots ,{\mathbf{mlast}}$.
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, ${\mathbf{mfirst}}>{\mathbf{mlast}}$, or k < 0${\mathbf{k}}<0$, or l < 0${\mathbf{l}}<0$, or na < (k + 1) × (l + 1)$\mathit{na}<\left({\mathbf{k}}+1\right)×\left({\mathbf{l}}+1\right)$, or nwork < k + 1$\mathit{nwork}<{\mathbf{k}}+1$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, ${\mathbf{ymin}}\ge {\mathbf{ymax}}$, or ${\mathbf{y}}<{\mathbf{ymin}}$, or ${\mathbf{y}}>{\mathbf{ymax}}$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, ${\mathbf{xmin}}\ge {\mathbf{xmax}}$, or x(i) < xmin${\mathbf{x}}\left(i\right)<{\mathbf{xmin}}$, or x(i) > xmax${\mathbf{x}}\left(i\right)>{\mathbf{xmax}}$, for some i = mfirst,mfirst + 1, … ,mlast$i={\mathbf{mfirst}},{\mathbf{mfirst}}+1,\dots ,{\mathbf{mlast}}$.

## 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 (k + 1) × (m + l + 1)$\left(k+1\right)×\left(m+l+1\right)$, where m = mlastmfirst + 1$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_fit_2dcheb_lines (e02ca), which provides the double array a in the required form. For this use, the values of ymin${y}_{\mathrm{min}}$ and ymax${y}_{\mathrm{max}}$ supplied to the present function must be the same as those supplied to nag_fit_2dcheb_lines (e02ca). The same applies to xmin${x}_{\mathrm{min}}$ and xmax${x}_{\mathrm{max}}$ if they are independent of y$y$. If they vary with y$y$, their values must be consistent with those supplied to nag_fit_2dcheb_lines (e02ca) (see Section [Further Comments] in (e02ca)).
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$y$, when, for example, other segments of x are associated with other values of y$y$. Such a case arises when, after using nag_fit_2dcheb_lines (e02ca) 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 function are set respectively (in terms of parameters of nag_fit_2dcheb_lines (e02ca)) to x, y(S)${\mathbf{y}}\left(S\right)$, 1 + i = 1s1m(i)$1+\sum _{i=1}^{s-1}{\mathbf{m}}\left(i\right)$ and i = 1sm(i)$\sum _{i=1}^{s}{\mathbf{m}}\left(i\right)$, the function will compute values of the polynomial surface at all data points which have y(S)${\mathbf{y}}\left(S\right)$ as their y$y$ coordinate (from which values the residuals of the fit may be derived).

## Example

function nag_fit_2dcheb_eval_example
mfirst = int64(1);
k = int64(3);
l = int64(2);
x = [0.5;
1;
1.5;
2;
2.5;
3;
3.5;
4;
4.5];
xmin = 0.1;
xmax = 4.5;
y = 1;
ymin = 0;
ymax = 4;
a = [15.3482;
5.15073;
0.1014;
1.14719;
0.14419;
-0.10464;
0.04901;
-0.00314;
-0.00699;
0.00153;
-0.00033;
-0.00022];
[ff, ifail] = nag_fit_2dcheb_eval(mfirst, k, l, x, xmin, xmax, y, ymin, ymax, a)

ff =

2.0812
2.1888
2.3018
2.4204
2.5450
2.6758
2.8131
2.9572
3.1084

ifail =

0

function e02cb_example
mfirst = int64(1);
k = int64(3);
l = int64(2);
x = [0.5;
1;
1.5;
2;
2.5;
3;
3.5;
4;
4.5];
xmin = 0.1;
xmax = 4.5;
y = 1;
ymin = 0;
ymax = 4;
a = [15.3482;
5.15073;
0.1014;
1.14719;
0.14419;
-0.10464;
0.04901;
-0.00314;
-0.00699;
0.00153;
-0.00033;
-0.00022];
[ff, ifail] = e02cb(mfirst, k, l, x, xmin, xmax, y, ymin, ymax, a)

ff =

2.0812
2.1888
2.3018
2.4204
2.5450
2.6758
2.8131
2.9572
3.1084

ifail =

0