PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_fit_1dcheb_eval2 (e02ak)
Purpose
nag_fit_1dcheb_eval2 (e02ak) evaluates a polynomial from its Chebyshev series representation, allowing an arbitrary index increment for accessing the array of coefficients.
Syntax
Description
If supplied with the coefficients
, for
, of a polynomial
of degree
, where
nag_fit_1dcheb_eval2 (e02ak) returns the value of
at a user-specified value of the variable
. Here
denotes the Chebyshev polynomial of the first kind of degree
with argument
. It is assumed that the independent variable
in the interval
was obtained from your original variable
in the interval
by the linear transformation
The coefficients
may be supplied in the array
a, with any increment between the indices of array elements which contain successive coefficients. This enables the function to be used in surface fitting and other applications, in which the array might have two or more dimensions.
The method employed is based on the three-term recurrence relation due to Clenshaw (see
Clenshaw (1955)), with modifications due to Reinsch and Gentleman (see
Gentleman (1969)). For further details of the algorithm and its use see
Cox (1973) and
Cox and Hayes (1973).
References
Clenshaw C W (1955) A note on the summation of Chebyshev series Math. Tables Aids Comput. 9 118–120
Cox M G (1973) A data-fitting package for the non-specialist user NPL Report NAC 40 National Physical Laboratory
Cox M G and Hayes J G (1973) Curve fitting: a guide and suite of algorithms for the non-specialist user NPL Report NAC26 National Physical Laboratory
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:
– int64int32nag_int scalar
-
, the degree of the given polynomial .
Constraint:
.
- 2:
– double scalar
- 3:
– double scalar
-
The lower and upper end points respectively of the interval
. The Chebyshev series representation is in terms of the normalized variable
, where
Constraint:
.
- 4:
– double array
-
la, the dimension of the array, must satisfy the constraint
.
The Chebyshev coefficients of the polynomial . Specifically, element
must contain the coefficient , for . Only these elements will be accessed.
- 5:
– int64int32nag_int scalar
-
The index increment of
a. Most frequently, the Chebyshev coefficients are stored in adjacent elements of
a, and
ia1 must be set to
. However, if, for example, they are stored in
, then the value of
ia1 must be
.
Constraint:
.
- 6:
– double scalar
-
The argument at which the polynomial is to be evaluated.
Constraint:
.
Optional Input Parameters
None.
Output Parameters
- 1:
– double scalar
-
The value of the polynomial .
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , |
or | , |
or | . |
-
-
x does not satisfy the restriction
.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The rounding errors are such that the computed value of the polynomial is exact for a slightly perturbed set of coefficients . The ratio of the sum of the absolute values of the to the sum of the absolute values of the is less than a small multiple of .
Further Comments
The time taken is approximately proportional to .
Example
Suppose a polynomial has been computed in Chebyshev series form to fit data over the interval
. The following program evaluates the polynomial at
equally spaced points over the interval. (For the purposes of this example,
xmin,
xmax and the Chebyshev coefficients are supplied
.
Normally a program would first read in or generate data and compute the fitted polynomial.)
Open in the MATLAB editor:
e02ak_example
function e02ak_example
fprintf('e02ak example results\n\n');
xmin = -0.5; xmax = 2.5;
a = [2.53213 1.13032 0.2715 0.04434 0.00547 0.00054 4e-05];
n = int64(6);
ia1 = int64(1);
m = 21;
dx = (xmax-xmin)/(m-1);
x = [xmin:dx:xmax];
for i = 1:m
[fit(i), ifail] = e02ak( ...
n, xmin, xmax, a, ia1, x(i));
end
sol = [x; fit];
fprintf(' x p(x)\n');
fprintf('%9.4f %9.4f\n',sol(1:2,1:5:21));
fig1 = figure;
plot(x,fit);
title('Evaluation of Chebyshev Polynomial');
xlabel('x');
ylabel('p(x)');
legend('fit','exp(x)');
e02ak example results
x p(x)
-0.5000 0.3679
0.2500 0.6065
1.0000 1.0000
1.7500 1.6487
2.5000 2.7183
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015