The accuracy and speed of function approximations – part 2
In part 1 we took a look at two different function approximations: a quadratic polynomial and a truncated Taylor polynomial. The Taylor polynomial was more accurate over the plotted interval – can we improve the quadratic approximation?
The quadratic equation is fine in some cases. If you want to create a swinging hammer, a wave or the movement for a platform; this approximation is fine. But we can add some extra precision to the function and get it to be even more accurate. The new function looks like this:
The first function f defines the sine approximation and the second function g adds some extra precision, producing a fourth-degree polynomial on this interval. The result will look like this:
- sin(x)
- g(x)
Error: g(x) − sin(x)
Show data
| x | sin(x) | g(x) | Error |
|---|---|---|---|
| 0 | 0.00000 | 0.00000 | +0.00000 |
| π/8 | 0.38268 | 0.38213 | -0.00055 |
| π/4 | 0.70711 | 0.70781 | +0.00071 |
| 3π/8 | 0.92388 | 0.92432 | +0.00044 |
| π/2 | 1.00000 | 1.00000 | +0.00000 |
| 5π/8 | 0.92388 | 0.92432 | +0.00044 |
| 3π/4 | 0.70711 | 0.70781 | +0.00071 |
| 7π/8 | 0.38268 | 0.38213 | -0.00055 |
| π | 0.00000 | -0.00000 | +0.00000 |
We are nearly unable to distinguish the two lines from each other. The rounded coefficients give approximate agreement at 0, π/2 and π. This corrected polynomial is more accurate than the Taylor polynomial used here over the plotted interval – but accuracy is not everything. We will take a look at the performance in part 3.