Introduction

This paper presents a method to approximate $sin(x)$ with high precision and relatively low computational cost. The approximation employs a straightforward polynomial transformation. Specifically, it uses the cubic $3x^2-2x^3$, also known as $smoothstep$, to approximate $sin(x)$ in a limited domain.

Context

  1. Define a function $f$ such that $f(x)=2(3x^2-2x^3)-1$. Therefore, $f(x)=6x^2-4x^3-1$.
  2. Now, define a new function $h$ such that $h(x)=f(\frac{2x+\pi}{2\pi})$. Consequently, $h(x)$ approximates $sin(x)$ over the range $[-\frac{\pi}{2},\frac{\pi}{2}]$. However, the precision of this approximation is low.

sin(x) in green, h(x) in blue and sin(x) - h(x) in red.

sin(x) in green, h(x) in blue and sin(x) - h(x) in red.

Improving the approximation

  1. To better approximate $sin(x)$ using $h(x)$, we first need to define a new function, $g(x)$, where $g(x) = h(x) \cdot n + m$.

  2. Take two values $x_1$and $x_2$ from the range $[0,\frac{\pi}{2}]$ where $x_2\geq x_1$

  3. Solve for $n$ and $m$ in the equations $g(x_1)=sin(x_1)$ and $g(x_2)=sin(x_2)$. Then, $g(x)\approx sin(x)$ for the range $[x_1, x_2]$.

    1. Solving the equations:

      $$ g(x_1)=sin(x_1)\\ h(x_1)\cdot n+m=sin(x_1)\\ m=sin(x_1)-h(x_1)\cdot n\\ \\\ \\ g(x_2)=sin(x_2)\\ h(x_2)\cdot n+m=sin(x_2)\\ h(x_2)\cdot n+sin(x_1)-h(x_1)\cdot n=sin(x_2)\\ (h(x_2)-h(x_1))n=sin(x_2)-sin(x_1)\\ n=\frac{sin(x_2)-sin(x_1)}{h(x_2)-h(x_1)}\\ $$

  4. An interesting fact is that the precision of the approximation depends on the difference between $x_1$ and $x_2$. When this difference is small, the precision is remarkably high within the range $[x_1,x_2]$, but considerably low outside this range.

The graphs from the previous image have been dashed, g(x) is in orange and sin(x)-g(x) is the non dashed red line. The two values chosen were pi/3 for x1 and x1 + 0.1 for x2.

The graphs from the previous image have been dashed, g(x) is in orange and sin(x)-g(x) is the non dashed red line. The two values chosen were pi/3 for x1 and x1 + 0.1 for x2.

Usability

As a standalone process this method does not produce remarkable results, When you consider the need to calculate the sines of $x_1$and $x_2$.

To enhance the efficacy of this method, we could divide the range $[0, \frac{\pi}{2}]$ into a collection, $S$, and pré compute the sines of each element within this collection. Once we have these pré calculated sine values, we can use them to perform interpolation of $sin(x)$ between the elements of $S$.

This strategy leverages the computational power of pré computation, where we calculate the sine values of the elements of $S$ beforehand rather than in real-time.

Conclusion

Using this method we can achieve a highly precise approximation of $sin(x)$ but with the additional cost of pré computing and storing the sines for $S$.