Q:

projection of a function on an orthogonal set

I'm currently trying to solve an equation of the form
$$f(x) = \sum_m\,a_m\,\varphi_m(x)$$
and it's required me to project this equation on a different set of functions 
$$\{\phi_m(x)\}$$
that is orthonormal on the interval (a,b). 
How do I execute such kind of projection?

A:

I think the coefficients of $f$ on the new basis should be given by
\begin{align}
a'_n=\int_a^b f(x)\phi_n(x)w(x)dx
  &=\int_a^b \sum_m a_m\varphi_m(x)\phi_n(x)w(x)dx\\
  &=\sum_m a_m\int_a^b \varphi_m(x)\phi_n(x)w(x)dx\\
\end{align}
supposing the integral-sum exchange is possible and where $w(x)$ is the weight function of the given scalar product.

