-
Notifications
You must be signed in to change notification settings - Fork 36
Tutorial 2 of 5: switching to relative error
In the previous section, we saw that lolremez
looked for a polynomial P(x) and the smallest error value E such that:
Where
A look at the error graph indicates that the error values in -1 and 1 are the same but the relative error values are not: it is about 0.15% for -1 whereas it is about 0.02% for 1.
We actually want a polynomial
Fortunately lolremez
is able to find such a polynomial, too.
lolremez --degree 4 --range -1:1 "exp(x)" "exp(x)"
See the subtle change? exp(x)
is now passed twice; the second argument is called the weight function. We are now minimising the following expression:
Where
After all the iterations the output should be as follows:
/* Approximation of f(x) = exp(x)
* with weight function g(x) = exp(x)
* on interval [ -1.0000000000000000000, 1.0000000000000000000 ]
* with a polynomial of degree 4. */
float f(float x)
{
float u = 3.9962914225208867552e-2f;
u = u * x + 1.7648623219024696305e-1f;
u = u * x + 5.0289865085404914825e-1f;
u = u * x + 9.9793872910703643074e-1f;
return u * x + 9.9962789571721377560e-1f;
}
Again, the polynomial and the original function are undistinguishable:
However, the error curve now looks like this:
We accomplished our goal: the relative error is minimised; it is about 0.05% for -1 and 0.05% for 1 (versus 0.15% and 0.02% respectively).
You should now be able to weigh your error function to control the final error curve of the minimax polynomial!
Please report any trouble you may have had with this document to [email protected]. You may then carry on to the next section: changing variables for simpler polynomials.