NAG C Library Function Document

nag_2d_cheb_eval (e02cbc)


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


#include <nag.h>
#include <nage02.h>
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)


This function evaluates a bivariate polynomial (represented in double Chebyshev form) of degree k in one variable, x-, and degree l in the other, 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 xmin and xmax are the ends of the range of x which has been transformed to the range -1 to +1 of x-. ymin and ymax are correspondingly for y. See Section 9). For this reason, the function has been designed to accept values of x and y rather than x- and y-, and so requires values of xmin, 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
where Tix- is the Chebyshev polynomial of the first kind of degree i and argument x-, and Tjy- 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 12aij, instead of simply aij, and the coefficient with both i and j zero is written 14a0,0.
The function first forms ci=j=0laijTjy-, with ai,0 replaced by 12ai,0, for each of i=0,1,,k. The value of the double series is then obtained for each value of x, by summing ci×Tix-, with c0 replaced by 12c0, over i=0,1,,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


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 9).
Constraint: mlastmfirst.
3:     k IntegerInput
4:     l IntegerInput
On entry: the degree k of x and l of y, respectively, in the polynomial.
Constraint: k0 and l0.
5:     x[mlast] const doubleInput
On entry: x[i-1], for i=mfirst,,mlast, must contain the x values at which the evaluation is required.
Constraint: xminx[i-1]xmax, for all i.
6:     xmin doubleInput
7:     xmax doubleInput
On entry: the lower and upper ends, xmin and xmax, 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: xmax>xmin.
8:     y doubleInput
On entry: the value of the y coordinate of all the points at which the evaluation is required.
Constraint: yminyymax.
9:     ymin doubleInput
10:   ymax doubleInput
On entry: the lower and upper ends, ymin and ymax, of the range of the variable y (see Section 3).
Constraint: ymax>ymin.
11:   ff[mlast] doubleOutput
On exit: ff[i-1] gives the value of the polynomial at the point xi,y, for i=mfirst,,mlast.
12:   a[dim] const doubleInput
Note: the dimension, dim, of the array a must be at least k+1×l+1.
On entry: the Chebyshev coefficients of the polynomial. The coefficient aij defined according to the standard convention (see Section 3) must be in a[i×l+1+j].
13:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
On entry, k=value and l=value.
Constraint: k0 and l0.
On entry, mfirst=value and mlast=value.
Constraint: mfirstmlast.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Unexpected internal failure when evaluating the polynomial.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
On entry, xmin=value and xmax=value.
Constraint: xmin<xmax.
On entry, y=value and ymax=value.
Constraint: yymax.
On entry, y=value and ymin=value.
Constraint: yymin.
On entry, ymin=value and ymax=value.
Constraint: ymin<ymax.
On entry, I=value, x[I-1]=value and xmax=value.
Constraint: x[I-1]xmax.
On entry, I=value, x[I-1]=value and xmin=value.
Constraint: x[I-1]xmin.


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.

Parallelism and Performance

nag_2d_cheb_eval (e02cbc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Further Comments

The time taken is approximately proportional to k+1×m+l+1, where m=mlast-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 ymin and ymax supplied to the present function must be the same as those supplied to nag_2d_cheb_fit_lines (e02cac). The same applies to xmin and xmax 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 9 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, yS, 1+i=1 s-1mi and i=1smi, the function will compute values of the polynomial surface at all data points which have y[S-1] as their y coordinate (from which values the residuals of the fit may be derived).


This example reads data in the following order, using the notation of the argument list above:
Nkl a[i-1], for ​i=1,2,,k+1×l+1 yminymax y[i-1]Mi-1xmin[i-1]xmax[i-1]X1iXMi, for ​i=1,2,,N.  
For each line y=y[i-1] the polynomial is evaluated at Mi equispaced points between X1i and XMi inclusive.

Program Text

Program Text (e02cbce.c)

Program Data

Program Data (e02cbce.d)

Program Results

Program Results (e02cbce.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 Example Program Evaluation of Least-squares Bi-variate Polynomial Fit P(x,y) gnuplot_plot_1 gnuplot_plot_2 0 0.5 1 1.5 2 2.5 3 3.5 4 y 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 x −10 −5 0 5 10 15