Article View: sci.math.num-analysis
Article #232Re: Chebyshev approximation puzzle
From: Andrew Haley
Date: Tue, 11 Aug 1992 11:29
Date: Tue, 11 Aug 1992 11:29
42 lines
1834 bytes
1834 bytes
ajayshah@almaak.usc.edu (Ajay Shah) writes:
: I was playing with the Numerical Recipes code which calculates
: the chebyshev approximation of a user-specified function.
: To convince myself it works, I tried to approximate the function
: f(x) = T_0(x) - 2T_1(x) + 3T_2(x) - T_4(x) on (-1, 1). I expect him
: to recover the true fourier coefficients (1, -2, 3, -1, 0, 0, 0, ...).
:
: The puzzle is: the approximation function (named chebft) correctly
: recovers the coefficients -2, 3, -1. It fails on the first one (the
: constant). It returns 2 instead of 1. Higher order terms are
: correctly set to 0.
:
: At the same time, when I compare the approximation-evaluation vs. the
: function evaluation, there is no error.
:
: What may I be missing?
:
: -ans.
:
: In case you would like to play with it:
:
: double f(double x)
: {
: int i;
: double t[4], constants[4] = {1,-2,3,-1}, sum=0;
: t[0] = 1;
: t[1] = x;
: t[2] = 2*x*x - 1;
: t[3] = 4*x*x*x - 3*x;
: for (i=0; i<4; i++) sum += t[i]*constants[i];
: return sum;
: }
: --
: Ajay Shah, (213)749-8133, ajayshah@usc.edu
The Numerical recipes code includes a kluge to improve the efficiency
of the Chebyshev evaluation function. The first term of a Chebyshev
series is conventinally multiplied by two. To allow the evaluation
function to ignore this fact, the first coefficient in the output
array is doubled.
Andrew.
Technical Details
Message-ID:
<1360@eouk9.eoe.co.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!eoe!ahaleyReferences:
<l826dvINN4bn@almaak.usc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!eoe!ahaley From: ahaley@eoe.co.uk (Andrew Haley) Newsgroups: sci.math.num-analysis Subject: Re: Chebyshev approximation puzzle Message-ID: <1360@eouk9.eoe.co.uk> Date: 11 Aug 92 11:29:01 GMT References: <l826dvINN4bn@almaak.usc.edu> Organization: EO Europe Limited, Cambridge, UK Lines: 42 X-Newsreader: Tin 1.1 PL3