Changes between Version 1 and Version 2 of doc/maths/remez/tutorial-exponential
- Timestamp:
- Dec 28, 2011, 11:17:19 PM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
doc/maths/remez/tutorial-exponential
v1 v2 1 1 = Remez tutorial first example: exp(x) = 2 2 3 This section is a hands-on example of the Lol Remez toolkit. 3 In this section we are going to approximate the ''exp(x)'' function using a polynomial. 4 5 This should be a hands-on example of the Lol Remez toolkit. 4 6 5 7 == Source code == … … 31 33 == Compilation == 32 34 35 If you are using LolRemez, just put the above source code in `remez.cpp` and type: 36 37 {{{ 38 make 39 }}} 40 41 == Execution == 42 43 To launch the test, type: 44 45 {{{ 46 ./remez 47 }}} 48 33 49 After all the iterations the output should be as follows: 34 50 35 36 Let’s say we want to approximate the following function:37 38 51 {{{ 39 #!latex 40 \[f(x) = \e^x\] 52 Final error: 5.462771976237482581009771665937582411463e-4 53 Polynomial estimate: 54 x**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 41 59 }}} 42 60 61 == Using the results == 62 63 The above results can be used in a C++ implementation: 64 65 {{{ 66 #!cpp 67 double 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 81 Plotting the real exponential function and our `fastexp` function gives the following curves: 82 83 [[Image(fastexp.png, nolink)]] 84