Skip to content

LMesaric/ChebyshevPolyfit

Repository files navigation

ChebyshevPolyfit

Approximation of a function f(x) on interval [a,b] by a polynomial of degree N with the help of Chebyshev polynomials.

Approximation is done as follows:

  • Calculate the Taylor series expansion of f(x) around x=C.
  • Iteratively replace terms of higher order than N with their approximation by Chebyshev polynomial.
  • Repeat, using higher degree Taylor series.
  • Final approximation is the one that has the lowest maximum error.

Maximum error is defined as the maximum absolute difference between the approximation and the original function f(x) on the specified interval [a,b].

Finding optimal C is the most interesting part. Taking C=0 will give the Maclaurin series, which is good for even functions like f3(x) and f4(x). Taking C=(a+b)/2 gives much better results for f2(x).

Hand-picked C=0.8762 for f1(x) and C=0.6113 for f2(x) gave the best results in terms of maximum error, but after seeing the error function (first image) it is obvious that using C=(a+b)/2=0.5 (second image) gives results which are more consistent. Since the small improvement did not increase the number of correct decimal digits, generally speaking, taking C=0.5 might be a better solution.

Below are approximations for hand-picked values of C.

Approximation results

f1(x) = ex

Coefficients for exp(x) on the interval [0, 1] with C=0.8762:

Coefficient Term
+0.0.001812583342355 x6
+0.00802002064194580 x5
+0.04196707939319135 x4
+0.16639182169042781 x3
+0.50009994005663482 x2
+0.99998761032346109 x
+1.00000138583625075 1

Maximum error on that interval: 1.387174778327080e-06

f2(x) = ln(1+x)

Coefficients for ln(1+x) on the interval [0, 1] with C=0.6113:

Coefficient Term
-0.03120137898937330 x6
+0.10196463478682490 x5
-0.18725593916599687 x4
+0.30301542826567001 x3
-0.49295760517944778 x2
+0.99942287921168635 x
+0.00008118594007705 1

Maximum error on that interval: 8.121660103074230e-05

f3(x) = sin(x)/x

Coefficients for sin(x)/x on the interval [-1, 1] with C=0:

Coefficient Term
+0.00000269375975766 x8
-0.00019835866408658 x6
+0.00833331406945632 x4
-0.16666666426123592 x2
+0.99999999995192540 1

Maximum error on that interval: 4.805667042378870e-11

f4(x) = cos(x)

Coefficients for cos(x) on the interval [-1, 1] with C=0:

Coefficient Term
+0.00002412120108317 x8
-0.00138829603431855 x6
+0.04166645537534186 x4
-0.49999997362171781 x2
+0.99999999947287566 1

Maximum error on that interval: 5.271243440664400e-10

Errors in approximations

Approximations from tables above:

ChebyshevWithSpecCorrection.png

Approximations using Taylor series expansion around the central point, C=(a+b)/2:

ChebyshevWithoutSpecCorrection.png

Approximations using integrals, similar to C=0:

ChebyshevIntegral.png

Related Projects