TITLE: Fitting $\cos(x)$ with a polynomial
QUESTION [29 upvotes]: Consider the graph of $\cos(x)$ on the interval $[-\pi/2,\pi/2]$. It looks very close to a parabola. I would like to find the parabola (or possibly family of parabolas) that "fit" the $\cos$ function the best on this interval.
By "fit" the best, I mean I want to minimize the absolute area between the curves as much as possible, i.e. minimize $$\int_{-\pi/2}^{\pi/2}|\cos(x)-p_2(x)|dx,$$
where $p_2$ is a degree $2$ polynomial.
My initial approach was to look at the Taylor approximation about $x=0$ of degree $2$
$$\cos(x)\approx1-\frac {x^2}2$$

The area between these curves is $2-\pi-\frac{\pi^3}{24}\approx0.15403$. Surely we can do better.
I then looked at the interpolating polynomial through the points $(-\pi/2,0),(0,1),(\pi/2,0)$, which gives the function $1-\frac{4x^2}{\pi^2}$.

The area between these two curves is $\frac23(\pi-3)\approx0.094395$. Better!
Next, I tried looking what quadratic, with vertex $(0,1)$, satisfies $$\int_{-\pi/2}^{\pi/2}\cos(x)-p_2(x)dx=0.$$
We then find that $p_2(x)=1-\frac{12(\pi-2)}{\pi^3}x^2$. 

So, there area between these two curves is $0$, but the absolute area is approximately $0.0539276$. Checking numerically, this appears to be the best-fitting parabola that has vertex $(0,1)$.

Is the polynomial $p(x)=1-\frac{12(\pi-2)}{\pi^3}x^2$ the unique quadratic that minimizes $$\int_{-\pi/2}^{\pi/2}|\cos(x)-p_2(x)|dx,$$
  where $p_2$ is a degree two polynomial?

Of course, it could be that there is a better-fitting polynomial that does not have its vertex at $(0,1)$. If not, then I simply ask:

Find a quadratic polynomial $p_2(x)$ that minimizes $$\int_{-\pi/2}^{\pi/2}|\cos(x)-p_2(x)|dx.$$

Now, this can be extended to other degree polynomials. For example, the best fitting constant is $c=\sqrt{2}/2$, and that gives $$\int_{-\pi/2}^{\pi/2}|\cos(x)-\frac{\sqrt2}2|dx=2(\sqrt2-1)\approx0.82843.$$ This raises my more general question.

Let $n\in\mathbb{N}$ and let $p_n(x)$ be an $n$th degree polynomial. For each $n$, what polynomial minimizes  $$\int_{-\pi/2}^{\pi/2}|\cos(x)-p_n(x)|dx?$$

REPLY [3 votes]: Just examples of approximations by such polynomials. 
With comparison of Taylor approximations.
Here $t_n(x)$: degree-$n$ polynomials given from Taylor series
$$
\cos(x) = 1 - \frac{1}{2!} x^2 + \frac{1}{4!}x^4 - \frac{1}{6!} x^6 + \ldots
$$
And  $p_n(x)$: "best fitting" polinomials found empirically.
\begin{array}{|c|l|l|}
\hline
n & t_n(x) \mbox { or } p_n(x) & \epsilon & -\log_{10}(\epsilon) \\
\hline
2 & t_2(x)=1.000000 - 0.500000x^2 & 0.150335 & 0.823 \\
2 & p_2(x)=0.985095 - 0.427001x^2 & 0.044907 & 1.348 \\
\hline
4 & t_4(x)= 1.0000000 - 0.5000000x^2 + 0.0416667x^4 & 0.0090497 & 2.043 \\
4 & p_4(x)= 0.9996916 - 0.4969942x^2 + 0.0375584x^4 & 0.0009478 & 3.023 \\
\hline
6 & t_6(x)=1.00000000-0.50000000x^2+0.04166667x^4-0.00138889x^6 & 3.1380\times10^{-4} & 3.503 \\
6 & p_6(x)=0.99999658-0.49994448x^2+0.04153112x^4-0.00128529x^6 & 1.0604\times10^{-5} & 4.975 \\
\hline
8 & t_8(x)=1.0000000000-0.5000000000x^2+0.0416666667x^4-0.0013888889x^6+0.0000248016x^8 & 7.0852\times10^{-6} & 5.150 \\
8 & p_8(x)=0.9999999763-0.4999994242x^2+0.0416644880x^4-0.0013860546x^6+0.0000233125x^8 & 7.3437\times10^{-8} & 7.134 \\
\hline
\end{array}