Minimize distance between polynomials, of a certain form, with Laguerre polynomials A typical problem that I may encounter on an upcoming test looks like this:

Find the polynomial $P(x)$ of a degree less than or equal to three
  that minimizes
$$\int_0^\infty (x^4 - P(x))^2xe^{-x}\rm{d}x.$$

In the course we have been presented with a theorem that says that if $\{\phi_n\}$ is an orthonormal basis in $L^2$ and $f\in L^2$ then $\sum c_n \phi_n$ minimizes the distance if $c_n = \langle f, \phi_n\rangle$ for each $n$.
In the case of the problem above the basis that should be used is the Laguerre polynomials $L^1_n$, i.e. $P(x)=\sum_0^3 c_n L_n^1$. I can solve this type of problems by looking the weight $xe^{-x}$ which is characteristic for Laguerre polynomials. However I don't really understand how to go from the theorem to the solution of this problem, with an expression of the form as in the sample problem above? I would appreciate an explanation of the problem so that I can understand what I am doing.
 A: The method of finding a solution in this sort of problem is the standard technique of projecting a vector onto an orthonormal basis wrt to some inner product.  I'll restate it in terms of linear algebra terms as it might make it easier to see.
First you have the vector space $V$ of polynomials on which an inner product is defined:
$$\langle p, q \rangle = \int_0^\infty p(x)q(x)xe^{-x}dx$$
where $p, q$ are polynomials.
As you pointed out the Generalized Laguerre Polynomials $L^1_n(x)$ are an orthonormal basis with respect to this inner product.  i.e.
$$\langle L_m^1, L_n^1 \rangle = \delta_{mn}$$
You want to find the closest $3$rd degree polynomial to the vector $x^4$.  Since the first $3$ Laguerre polynomials span the space of $3$rd degree polynomials you want to project down onto them.  i.e. Find the polynomial $P(x)$ such that
$$\langle x^4 - P(x), x^4 - P(x) \rangle = ||x^4 - P(x)||^2 = \int_0^\infty (x^4 - P(x))^2 xe^{-x}dx$$
is minimized.
In it is a theorem that when you have an orthonormal basis, you can find the vector $P$ in the span of a subspace by projecting onto the basis vectors that span it.  In this case those basis elements are $L_0^1, L_1^1, L_2^1, L_3^1$.  So when you are computing $c_n = \langle x^4, L_n^1(x) \rangle$ you are computing these projections and the final polynomial is given by:
$$P(x) = \sum_{n=0}^3 c_n L_n^1(x)$$
