3

I was working on an approximation for the sine function, in which I needed to calculate the maximum error to work on a compensation polynomial. My approximation was this:

$$f(x) = \frac {4} {\pi^2} x (\pi - |x|)$$

Then, obviously the error is found by substracting that from $\sin(x)$. In order to find the x-coordinate of the maximum error I took the derivative and and set it equal to zero.

$$\begin{align*} \mathrm{err}(x) &= \sin(x) -f(x)\\ \mathrm{err}'(x) &= \cos(x) + \frac {8} {\pi^2}|x| - \frac 4 {\pi} \\ \mathrm{err}'(x) &= 0 \rightarrow \cos(x) = \frac 4 \pi - \frac 8 {\pi^2}|x| \end{align*}$$

But I'm only a highschool student and I have no knowledge of the maths required to solve that last equation, if possible. How would one go into solving that last equation exactly?

A small image:

enter image description here


For my particular purpose it would suffice by calculating the value numerically and continue, but just purely for interest I'd like to know the exact value. Not homework.

orlp
  • 10,508
  • 3
    Equations of that kind generally can't be solved exactly. – Qiaochu Yuan Feb 17 '12 at 17:58
  • Be careful about taking the derivative. The function $f(x) = |x|$ is not differentiable at $x = 0$, and so your function $err(x)$ is also not differentiable at $x = 0$. – JavaMan Feb 17 '12 at 17:58
  • @JavaMan: While you are right I am only interested in the range $(0, \pi)$ so it doesn't really matter. I know that $0$ and $\pi$ are zeroes of $f$ and $sin$, so $err$ is $0$ there anyway. – orlp Feb 17 '12 at 18:04
  • Would $\sin x=\cos(x-\frac{\pi}{2})=\sum\limits_{n=0}^\infty(-1)^n\frac{(x-\frac{\pi}{2})^{2n}}{(2n)!}$ help you any? It's a Taylor series, meaning that if you take the first few terms, at some value $x$, then the approximation error is equal to the next term with some value $\xi\in[0,|x|]$ in place of $x$. – bgins Feb 17 '12 at 18:18
  • @bgins: my previous attempts have been with Taylor series, my goal is to make a slightly imprecise but blazing fast $sin$ function. After trying to approximate $sin$ with parabolae I got much better results. My current best is 0.00109 worst and 0.000505 average error with 4 multiplications and 2 additions. – orlp Feb 17 '12 at 18:24
  • Searched "fast approximations to trigonometric functions". Found, for example (tip of the iceberg): http://www.research.scea.com/research/pdfs/RGREENfastermath_GDC02.pdf; http://sagenb.org/home/pub/717/. But that was a fast, approximate search. – bgins Feb 17 '12 at 18:28
  • There is probably also an architectural dimension to your project. Some applications are machine learning and simulation. Would yours benefit by exploiting GPU parallelism? If so, try adding 'cuda' to the search. Taylor's theorem and interpolation polynomial in numerical analysis can give precise statements about approximation errors (example search: 'numerical analysis interpolation error theorem'). Also: if you precompute $4/\pi^2$, you should only need one addition and two multiplications to get your $f(x)$. – bgins Feb 17 '12 at 20:13
  • @bgins: that's exactly what I do, but I've also added a second polynomial that boosts accuracy a lot. My code can be found here: https://gist.github.com/1855260 – orlp Feb 17 '12 at 20:36

0 Answers0