-
Notifications
You must be signed in to change notification settings - Fork 36
Tutorial 3 of 5: changing variables for simpler polynomials
In the previous section, we introduced function lolremez
looked for a polynomial
Where
We will now see that
An odd function is such that in all points,
An example of an odd function is
A reasonable expectation is that approximating an odd function over an interval centred at zero will lead to an odd polynomial. But due to the way the Remez exchange algorithm works, this is not necessarily the case. We can help the algorithm a little.
Suppose we want to approximate
We know
We notice that an odd polynomial
Another observation is that replacing
Now since
This is almost something lolremez
can deal with, if only there wasn’t this
That’s it! We have our minimax equation, and we can feed it to lolremez
.
lolremez --degree 4 --range 1e-50:pi*pi/4 "sin(sqrt(x))/sqrt(x)" "1/sqrt(x)"
Note: since
After all the iterations the output should be as follows:
/* Approximation of f(x) = sin(sqrt(x))/sqrt(x)
* with weight function g(x) = 1/sqrt(x)
* on interval [ 9.9999999999999999999e-51, 2.4674011002723396547 ]
* with a polynomial of degree 4. */
float f(float x)
{
float u = 2.4609388329975758276e-6f;
u = u * x + -1.9698112762578435577e-4f;
u = u * x + 8.3298294559966612167e-3f;
u = u * x + -1.6666236485125293496e-1f;
return u * x + 9.9999788400553332261e-1f;
}
We can therefore write the corresponding C++ function:
float fastsin(float x)
{
return x * f(x * x);
}
The obtained polynomial needs 5 constants for a maximum error of about 3.3381e-9 over
Again, the error curves match almost perfectly. It means that the odd coefficients in the minimax approximation of an even function play very little role.
You should now be able to give hints to the Remez solver through changes of variables, and find polynomials with fewer constants!
Please report any trouble you may have had with this document to [email protected]. You may then carry on to the next section: fixing lower-order parameters.