$4^\text{th}$ order polynomial approximation for: $f(x) = e^{-\cos(2\pi x)}$ I know how to find a polynomial approximation for a function $f(x)$ around a fixed number let's say $x=0$.
However I do not have an idea about how to solve the following:
Find a $4^\text{th}$ order polynomial approximation for:  $f(x) = e^{-\cos(2\pi x)}$, where $x \in [0,1]$ such that $\int_{0}^{\\1} |f(x) - p(x)|^2$ is minimized.
Could you please help me?
 A: $$\int_0^1(f(x)-A-Bx-Cx^2-Dx^3-Ex^4)^2dx$$
If you expand this, you get a quadratic in $A,B,C,D,E$.  
A: Using Michael's notation, you want to minimise
$$I(A,B,C,D,E) = \int_0^1(f(x)-p(x))^2dx = \int_0^1(f(x)-A-Bx-Cx^2-Dx^3-Ex^4)^2dx$$
So set
$$\frac{\partial I}{\partial A} = \frac{\partial I}{\partial B} = \frac{\partial I}{\partial C} = \frac{\partial I}{\partial D} = \frac{\partial I}{\partial E} = 0$$
For example,
$$\frac{\partial I}{\partial C} = \int_0^1\frac{\partial}{\partial C}\{(f(x)-A-Bx-Cx^2-Dx^3-Ex^4)^2\}dx = -2\int_0^1x^2(f(x)-p(x))dx$$
Setting this to zero gives $\int_0^1x^2f(x) = \int_0^1x^2p(x)dx$.
In this way, you get the five equations
$$\int_0^1f(x) = \int_0^1p(x)dx$$
$$\int_0^1xf(x) = \int_0^1xp(x)dx$$
$$\int_0^1x^2f(x) = \int_0^1x^2p(x)dx$$
$$\int_0^1x^3f(x) = \int_0^1x^3p(x)dx$$
$$\int_0^1x^4f(x) = \int_0^1x^4p(x)dx$$
The left-hand sides are constants that you can evaluate, and the right-hand sides are linear functions of $A,B,C,D,$ and $E$. So you get five linear equations in five unknowns, which you can solve by the usual means.
A: The preferred answer in this situation computes the projection using an orthogonal basis, where we measure orthogonality using the $L^2$ inner product, i.e. $\langle f,g \rangle = \int_0^1 f(x) g(x) dx$. Here the system of orthogonal polynomials is a small variant on the Legendre polynomials; namely, you want $p_n(x)=L_n(2x-1)$, where $L_n$ are the Legendre polynomials. Then the projection of $f$ is
$$g(x) = \sum_{n=0}^4 c_n p_n(x)$$
where 
$$c_n = \frac{\int_0^1 f(x) p_n(x) dx}{\int_0^1 p_n(x)^2 dx}.$$
Note that no system of linear equations is required.
The denominators are easy to compute (change variables back to $[-1,1]$, then use https://en.wikipedia.org/wiki/Legendre_polynomials#Orthogonality). The numerators are nontrivial integrals, which probably have no closed form solution, so that numerical methods will be required.
