GithubHelp home page GithubHelp logo

lmesaric / chebyshevpolyfit Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 1.2 MB

Third project for DisCont Mathematics 2 @ FER

License: Apache License 2.0

M 32.04% MATLAB 67.96%
chebyshev-polynomials approximation matlab dismat2

chebyshevpolyfit's Introduction

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

chebyshevpolyfit's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.