Thread View: sci.math.num-analysis
2 messages
2 total messages
Started by Ajay Shah
Thu, 06 Aug 1992 12:23
Chebyshev approximation puzzle
Author: Ajay Shah
Date: Thu, 06 Aug 1992 12:23
Date: Thu, 06 Aug 1992 12:23
33 lines
1446 bytes
1446 bytes
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
Re: Chebyshev approximation puzzle
Author: 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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads