$\int_I x^n f(x)dx=0$ and $I$ open imply $f=0$ Let $I$ be a bounded interval of $\mathbb{R}$ and $f$ be a continuous function on $I$. 
Assume $I$ is closed, ie: $I=[a,b]$, and $\forall n\geq 0$, $\int_I x^n f(x)dx=0$. Then, one can show with Weierstrass approximation that $f=0$ on $I$. 
This can be done because, with this assumption, $I$ is compact so one can apply Weierstrass theorem. But someone told me that the result holds even though $I$ is open, ie: $I=(a,b)$.
How can this be done ?
 A: Viewing the problem as if it was about vectors in the space $L^2(X)$, we note that the spaces $L^2[a,b]$ and $L^2(a,b)$ are practicaly the same space ($L^2(X)$ is the space of square integrable, lebesgue measurable functions defined on the measurable space $X$).
This condition is equivalent to $f$ being orthogonal to a spanning set: $\{x^n\} _{n=1}^\infty$, and the only vector (function) that is orthogonal to a dense set is the zeroth vector.
Now, the zeroth vector in such spaces are functions that equal $0$ almost everywhere (up to a null set). Since $f$ is continuous, it must be $0$ everywhere.
A: If you assume that $f$ is absolutely integrable on $(a,b)$, then you can get what you want. To see this, suppose $g$ is continuous on $[a,b]$. Then the Weierstrass approximation theorem gives you a sequence $\{ g_n \}$ of polynomials on $[a,b]$ that converges uniformly to $g$. Therefore,
$$
        \left|\int_{a}^{b}g_n f dx - \int_{a}^{b}g fdx\right| \le \int_{a}^{b}|f(x)|dx\cdot\sup_{x\in [a,b]}|g_n(x)-g(x)|\rightarrow 0 \mbox{ as } n\rightarrow\infty.
$$
Because $\int_{a}^{b}g_n(x)f(x)dx = 0$ for all $n$, it follows that
$$
   \int_{a}^{b}g(x)f(x)dx=\lim_n \int_{a}^{b}g_n(x)f(x)dx=0.
$$
The above must hold for all $g \in C[a,b]$. Fix a subinterval $[c,d]\subset (a,b)$ and define $g_{\delta}(x)$ to be $f$ on $[c,d]$, to be $0$ on $(a,c-\delta)\cup(d+\delta,b)$, and to be linear and continuous on the remaining intervals $[c-\delta,c]\cup[d,d+\delta]$. Then
$$
        0=\lim_{\delta\downarrow 0}\int_{a}^{b}f(x)g_{\delta}(x)dx=\int_{c}^{d}f(x)^2dx.
$$
The above holds for all $a < c < d < b$. And $f(x)^2$ is continuous on $(a,b)$. By the Fundamental Theorem of Calculus,
$$
             0=\frac{d}{dy}\int_{c}^{y}f(x)^2dx=f(y)^2.
$$
A: You can apply Weierstrass on the intervals $[a+\frac1k,b-\frac1k]$ for natural $k>\frac 2{b-a}$.
