← All articles

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:

\[ \begin{aligned} f(x) &= 1.27323954x - 0.405284735 \cdot x^2 \\ g(x) &= .225 \cdot (f(x)^2 - f(x)) + f(x) \end{aligned} \]

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:

Sine and the corrected polynomial
  • sin(x)
  • g(x)
Show data
xsin(x)g(x)Error
00.000000.00000+0.00000
π/80.382680.38213-0.00055
π/40.707110.70781+0.00071
3π/80.923880.92432+0.00044
π/21.000001.00000+0.00000
5π/80.923880.92432+0.00044
3π/40.707110.70781+0.00071
7π/80.382680.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.

More in Algorithms

All 25 Algorithms articles →