Changes between Version 1 and Version 2 of doc/maths/remez/tutorial-exponential


Ignore:
Timestamp:
Dec 28, 2011, 11:17:19 PM (9 years ago)
Author:
sam
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • doc/maths/remez/tutorial-exponential

    v1 v2  
    11= Remez tutorial first example: exp(x) =
    22
    3 This section is a hands-on example of the Lol Remez toolkit.
     3In this section we are going to approximate the ''exp(x)'' function using a polynomial.
     4
     5This should be a hands-on example of the Lol Remez toolkit.
    46
    57== Source code ==
     
    3133== Compilation ==
    3234
     35If you are using LolRemez, just put the above source code in `remez.cpp` and type:
     36
     37{{{
     38make
     39}}}
     40
     41== Execution ==
     42
     43To launch the test, type:
     44
     45{{{
     46./remez
     47}}}
     48
    3349After all the iterations the output should be as follows:
    3450
    35 
    36 Let’s say we want to approximate the following function:
    37 
    3851{{{
    39 #!latex
    40 \[f(x) = \e^x\]
     52Final error: 5.462771976237482581009771665937582411463e-4
     53Polynomial estimate:
     54x**0*1.000090756764725753887362987792025308996
     55+x**1*9.973086551667860566788019540269306006270e-1
     56+x**2*4.988332174505582284710918757571761729419e-1
     57+x**3*1.773462612793916519454714108029230813767e-1
     58+x**4*4.415666059995979611944324860870682575219e-2
    4159}}}
    4260
     61== Using the results ==
     62
     63The above results can be used in a C++ implementation:
     64 
     65{{{
     66#!cpp
     67double fastexp(double x)
     68{
     69    const double a0 = 1.000090756764725753887362987792025308996;
     70    const double a1 = 9.973086551667860566788019540269306006270e-1;
     71    const double a2 = 4.988332174505582284710918757571761729419e-1;
     72    const double a3 = 1.773462612793916519454714108029230813767e-1;
     73    const double a4 = 4.415666059995979611944324860870682575219e-2;
     74
     75    return a0 + x * (a1 + x * (a2 + x * (a3 + x * a4)));
     76}
     77}}}
     78
     79== Analysing the results ==
     80
     81Plotting the real exponential function and our `fastexp` function gives the following curves:
     82
     83[[Image(fastexp.png, nolink)]]
     84