# Weight function and orthogonalization

If we have the weight function $w(x) = e^{-x}$, then what are the constant and linear polynomials $p_0(x)$, $p_1(x)$, that are orthogonal on $[0,\infty)$ w.r.t. $w(x)$?

And if $f(x) =\cos(x)$, what is the best linear approximation to $f(x)$ for the given weight?

I think you are interested in the Laguerre polynomials $L_n$, which form an orthonormal basis for the weighted space $L^2((0,\infty), e^{-x}\,dx)$. In particular, $L_0(x)=1$ and $L_1(x)=-x+1$.
To approximate $\cos x$, just compute its coefficients as $$c_n=\int_0^\infty \cos x L_n(x) e^{-x}\,dx$$ For example, I get $1/2, 1/2, 1/4, 0, -1/8, -1/8$ for $n=0,\dots,5$. The corresponding sum $$\sum_{n=0}^5 c_n L_n(x)= 1+\frac{1}8 x-\frac{7}{8}x^2+\frac{7}{24} x^3-\frac{1}{32} x^4+\frac{1}{960}x^5$$ gives this approximation:
This isn't picture-perfect but what can you expect from degree 5 polynomial. The weight $e^{-x}$ makes sure the approximation is okay at the beginning, but it does not care much about what happens when $x$ is large.