🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.math.num-analysis
Article #198

Chebyshev approximation puzzle

#198
From: Ajay Shah
Date: Thu, 06 Aug 1992 12:23
33 lines
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
Technical Details
Message-ID: <l826dvINN4bn@almaak.usc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!usc!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!usc!news
From: ajayshah@almaak.usc.edu (Ajay Shah)
Newsgroups: sci.math.num-analysis
Subject: Chebyshev approximation puzzle
Date: 6 Aug 1992 05:23:27 -0700
Organization: University of Southern California, Los Angeles, CA
Lines: 33
Sender: ajayshah@almaak.usc.edu (Ajay Shah)
Message-ID: <l826dvINN4bn@almaak.usc.edu>
NNTP-Posting-Host: almaak.usc.edu