Version 1 (modified by sam, 9 years ago) (diff)

--

Remez tutorial first example: exp(x)

This section is a hands-on example of the Lol Remez toolkit.

Source code

#include "lol/math/real.h"
#include "lol/math/remez.h"

using lol::real;
using lol::RemezSolver;

real f(real const &x) { return exp(x); }

int main(int argc, char **argv)
{
    RemezSolver<4, real> solver;
    solver.Run(-1, 1, f, 30);
    return 0;
}

What does this mean?

  • we declare function f which returns the exponential of 'x'.
  • we create a RemezSolver object for 4th-degree polynomials and real numbers.
  • we run the solver on the [-1,1] range, approximating function f for 30 iterations.

Compilation

After all the iterations the output should be as follows:

Let’s say we want to approximate the following function:

\[f(x) = \e^x\]

Attachments (2)

Download all attachments as: .zip