# Is it possible to use polynomial interpolation to show that $\cos(x) = \sum_{n=0}^{\infty} \frac{(-1)^nx^{2n}}{(2n)!}$?

Several months ago, I discovered that one can make use a system of linear equations to obtain a polynomial that approaches certain functions. And I know these is the series representation for:

$$\displaystyle \cos(x) = 1 - {x^{2} \over 2!} + {x^{4} \over 4!} - \cdots = \sum_{n=0}^{\infty} \frac{(-1)^nx^{2n}}{(2n)!}$$

So I decided to test this and try to obtain this series with the bakground I learned above. So I did the following:

I'd need a systems of equations in the following form:

$$\begin{cases} a_1 x_1+a_0=\cos(x_1) \\ a_1 x_2+a_0=\cos(x_2) \\ \end{cases}$$

$$\begin{cases} a_2 x^2_1+a_1 x_1+a_0=\cos(x_1) \\ a_2 x^2_2+a_1 x_2+a_0=\cos(x_2) \\ a_2 x^2_3+a_1 x_3+a_0=\cos(x_3) \\ \end{cases}$$

$$\begin{cases} a_3 x^3_1+a_2 x_1^2+a_1 x_1+a_0=\cos(x_1) \\ a_3 x^3_2+a_2 x^2_2+a_1 x_2+a_0=\cos(x_2) \\ a_3 x^3_3+a_2 x^2_3+a_1 x_3+a_0=\cos(x_3) \\ a_3 x^3_4+a_2 x^2_4+a_1 x_4+a_0=\cos(x_4)\\ \end{cases}$$

So, find a solution for $a_n$ should give me the coefficients of a polynomial that approaches the $\cos(x)$ at $x_n$. And hence, I did this:

$$\begin{cases} a_0+\frac{\pi a_1}{4}=\frac{1}{\sqrt{2}} \\ a_0+\frac{\pi a_1}{2}=0 \\ \end{cases}$$

$$\begin{cases} a_0+\frac{\pi a_1}{4}+\frac{\pi ^2 a_2}{16}=\frac{1}{\sqrt{2}} \\ a_0+\frac{\pi a_1}{2}+\frac{\pi ^2 a_2}{4}=0 \\ a_0+\frac{3 \pi a_1}{4}+\frac{9 \pi ^2 a_2}{16}=-\frac{1}{\sqrt{2}} \\ \end{cases}$$

$$\begin{cases} a_0+\frac{\pi a_1}{4}+\frac{\pi ^2 a_2}{16}+\frac{\pi ^3 a_3}{64}=\frac{1}{\sqrt{2}} \\ a_0+\frac{\pi a_1}{2}+\frac{\pi ^2 a_2}{4}+\frac{\pi ^3 a_3}{8}=0 \\ a_0+\frac{3 \pi a_1}{4}+\frac{9 \pi ^2 a_2}{16}+\frac{27 \pi ^3 a_3}{64}=-\frac{1}{\sqrt{2}} \\ a_0+\pi a_1+\pi ^2 a_2+\pi ^3 a_3=-1 \\ \end{cases}$$

And (using Mathematica), I've found the solutions:

$$\begin{array}{cc} a_0= \sqrt{2} & a_1= -\frac{2 \sqrt{2}}{\pi } \\ \end{array}$$

$$\begin{array}{ccc} a_0= \sqrt{2} & a_1= -\frac{2 \sqrt{2}}{\pi } & a_2= 0 \\ \end{array}$$

$$\begin{array}{cccc} a_0= 1 & a_1= \frac{2 \left(8 \sqrt{2}-11\right)}{3 \pi } & a_2= -\frac{16 \left(\sqrt{2}-1\right)}{\pi ^2} & a_3= \frac{32 \left(\sqrt{2}-1\right)}{3 \pi ^3} \\ \end{array}$$

My thinking is that as we put more equations in the system for more values of $\cos$, it will give a polynomial that better approaches $\cos$. And as I put more equations with more values for cosine at the system, the solutions were:

$$\begin{array}{cc} a_0= \sqrt{2} & a_1= -\frac{2 \sqrt{2}}{\pi } \\ \end{array}$$

$$\begin{array}{ccc} a_0= \sqrt{2} & a_1= -\frac{2 \sqrt{2}}{\pi } & a_2= 0 \\ \end{array}$$

$$\begin{array}{cccc} a_0= 1 & a_1= \frac{2 \left(8 \sqrt{2}-11\right)}{3 \pi } & a_2= -\frac{16 \left(\sqrt{2}-1\right)}{\pi ^2} & a_3= \frac{32 \left(\sqrt{2}-1\right)}{3 \pi ^3} \\ \end{array}$$

$$\begin{array}{ccccc} a_0= 5-3 \sqrt{2} & a_1= -\frac{122-91 \sqrt{2}}{3 \pi } & a_2= -\frac{2 \left(129 \sqrt{2}-164\right)}{3 \pi ^2} & \\ a_3= \frac{16 \left(17 \sqrt{2}-22\right)}{3 \pi ^3} & a_4= -\frac{32 \left(3 \sqrt{2}-4\right)}{3 \pi ^4} \\ \end{array}$$

$$\begin{array}{cccccc} a_0= -5 \left(2 \sqrt{2}-3\right) & a_1= \frac{2 \left(707 \sqrt{2}-990\right)}{15 \pi } & a_2= -\frac{4 \left(222 \sqrt{2}-307\right)}{3 \pi ^2} &\\ a_3= \frac{8 \left(153 \sqrt{2}-214\right)}{3 \pi ^3} & a_4= -\frac{64 \left(12 \sqrt{2}-17\right)}{3 \pi ^4} & a_5= \frac{128 \left(7 \sqrt{2}-10\right)}{15 \pi ^5} \\ \end{array}$$

$$\begin{array}{ccccccc} a_0= 35-24 \sqrt{2} & a_1= \frac{8 \left(434 \sqrt{2}-615\right)}{15 \pi } & a_2= -\frac{4 \left(9014 \sqrt{2}-12725\right)}{45 \pi ^2} & \\ a_3= \frac{128 \left(31 \sqrt{2}-44\right)}{3 \pi ^3} & a_4= -\frac{32 \left(317 \sqrt{2}-452\right)}{9 \pi ^4} & a_5= \frac{1024 \left(7 \sqrt{2}-10\right)}{15 \pi ^5} & \\ a_6= -\frac{512 \left(7 \sqrt{2}-10\right)}{45 \pi ^6} \\ \end{array}$$

$$\begin{array}{cccccccc} a_0= -3 (16 \sqrt{2}-23) & a_1= \frac{2 \left(25220 \sqrt{2}-35733\right)}{105 \pi } & a_2= -\frac{4 \left(20270 \sqrt{2}-28671\right)}{45 \pi ^2} & \\ a_3= \frac{8 \left(19044 \sqrt{2}-26999\right)}{45 \pi ^3} & a_4= -\frac{32 \left(989 \sqrt{2}-1404\right)}{9 \pi ^4} & a_5= \frac{256 \left(360 \sqrt{2}-511\right)}{45 \pi ^5} & \\ a_6= -\frac{512 \left(55 \sqrt{2}-78\right)}{45 \pi ^6} & a_7= \frac{2048 \left(12 \sqrt{2}-17\right)}{315 \pi ^7} \\ \end{array}$$

Now, here I expected a miracle:

$\quad \quad \quad\quad \quad\quad$ I expected that somehow, the coefficients of $a_n$ converged to the coefficients of the series I gave in the beginning (because of the better polynomial that approaches $\cos$) but just by looking at it, this doesn't seems to be the case. But I don't know how to prove this is actually not the case: Is it possible that the method I employed could yield the results I expect or is it impossible?

I understand that my thinking is poorly justified and perhaps too vague but I want to know if something can be made with it or if it is possible to use polynomial interpolation to show that $\cos(x) = \sum_{n=0}^{\infty} \frac{(-1)^nx^{2n}}{(2n)!}$?

• Using polynomial interpolation you cannot get uniform convergence. I guess that that is probably the obstruction. – Mathematician 42 Nov 26 '16 at 21:19
• The Taylor expansion is the best polynomial approximation/interpolation of $f(x)$ on $x \in [-\epsilon,\epsilon]$ as $\epsilon \to 0$. If you don't let $\epsilon \to 0$ you might have some convergence problems with your sequence of interpolation polynomials – reuns Nov 26 '16 at 21:22
• These run far outside of the equation box for me. I recommend writing these terms in matrices if you know any linear algebra.... not only would this make it easier to write, but solving the equations might exhibit special symmetries in the matrix form you didn't notice prior that could help in determining whether $a_n$ approaches a fixed value $c_n$ – Brevan Ellefsen Nov 26 '16 at 22:58
• @BrevanEllefsen I know how to do in matrices. But it's more complicated to do on Mathematica. – Billy Rubina Nov 26 '16 at 23:17

The least squares fit polynomial to a function $f(x)$ over an interval $[a,b]$ is the polynomial $p(x)=a_0 + a_1x + \dots + a_dx^d$ with coefficients $a_i$ chosen to minimize $$\int_{a}^{b} (p(x) - f(x))^2 \, dx.$$

The least squares fit polynomial to $f(x)=\cos(x)$ over the interval $[-\pi,\pi]$ actually does approach the Taylor series polynomial as you increase the degree.

A faster and more numerically stable way to compute the least squares fit polynomial for $f(x)$ is to let $p(x)$ be a linear combination of orthogonal polynomials (such as the Legendre polynomials). In other words, let $p(x) = \sum_{i=0}^d a_i P_i(x),$ where $P_i(x)$ is the Legendre polynomial of degree $i.$ The solution for $a_i$ is then $$a_i = \frac{2i+1}{2} \int_{-1}^1 P_i(x) f(x) \, dx.$$

• But how can I see/prove it? From a few computations, the coefficients do not seem to be going to a common limit. – Billy Rubina Nov 27 '16 at 5:00
• I don't know a proof of this. I have only done numerical computations. Try degree 8, 10, and 12 polynomials. For these degrees, the $x^4$ coefficient is 0.0415223, 0.0416610, and 0.0416665 (getting very close to 1/24). Are you sure you are computing the least squares polynomial correctly? – J. Heller Nov 27 '16 at 6:08
• Also, use SVD (singular value decomposition) to solve for the coefficients of the polynomial (if you solve numerically rather than symbolically) because the linear system of equations is very ill-conditioned. – J. Heller Nov 27 '16 at 6:27
• @J.Heller a problem is that the sequence of least-square polynomials behave very badly with respect to some noise, that's why the orthogonal polynomials are preferred – reuns Nov 28 '16 at 4:27
• @OppaHilbertStyle "Elementary Numerical Analysis" by Conte and de Boor is good. The Wikipedia article on Legendre polynomials is also detailed enough to see how to derive the formula for $a_i$. – J. Heller Nov 28 '16 at 21:19

You can do what you wanted to do here with Mathematica.

Unprotect[Power]; 0^0 = 1;
ClearAll[sys, doit, a];
sys[n_?OddQ] := Table[With[{x = Pi (m - (n - 1)/2)/(n - 1)},
Sum[a[k] x^k/k!, {k, 0, n - 1}] == Cos[x]], {m, 0, n - 1}];
doit[n_?OddQ] := (soln = Solve[sys[n], Array[a, n, 0]][];
f[x_] := Sum[a[k] x^k/k!, {k, 0, n - 1}] /. soln);
doit; Print[soln, N[Table[soln[[n, 2]], {n, 7}], 5]];
Plot[{Cos[x], f[x]}, {x, -Pi, Pi}]
(*
{a -> 1, a -> 0, a -> (-517 + 270*Sqrt)/(5*Pi^2),
a -> 0, a -> (-216*(-68 + 39*Sqrt))/Pi^4,
a -> 0, a -> (46656*(-26 + 15*Sqrt))/Pi^6}
{1.0000, 0, -0.99996, 0, 0.99789, 0, -0.93361}
*)


The purpose of 0^0=1 is to avoid a glitch. The sys[] function returns a list of polynomial equations, The main doit[] function solves the polynomials equations to find the coefficients. The doit sets the function f[] to be a 6th degree polynomial with the coefficients found by solving the system of equations. The found coefficients are then printed and the Plot[] does a comparison of the actual Cos[] function with the found f[] polynomial function.

The key idea here is to interpolate the $$\,\cos\,$$ function at a set of points uniformly distributed over the whole interval $$\,[-\pi,\pi].$$ The difference in the function and its polynomial interpolation is pretty good even for $$\,n=7.$$ In fact, the coefficients are getting very close to the actual coefficients of the Taylor series.