Application of Fourier Series and Stone Weierstrass Approximation Theorem 

If $f \in C[0, \pi]$ and $\int_0^\pi f(x) \cos nx\, \text{d}x = 0$ , then $f = 0$


Define $ g(x) = \begin{cases}
         f(-x) & \text{if } -\pi \leq x < 0;\\
        f(x) & \text{if }  0 \leq x \leq \pi. \end{cases}$
which is an even function
So $g(x)$ can be written as $\sum_{n=0}^\infty a_n\cos (nx)$ for all $x \in [-\pi , \pi]$
$$\therefore \int_0^\pi f^2(x) \, dx = \int_0^\pi f(x) \left(\sum_{n=0}^\infty \cos(nx)\right) \, dx = \sum_{n=0}^\infty \int_0^\pi f(x) \cos(nx) \, dx = 0$$
$$\therefore \int_0^\pi f^2(x) \, dx =0,$$ we get $f(x) = 0$
I think this part is my true 
$$\text{If }f \in C[0 , \pi] \text{ and  } \int_o^\pi x^n f(x) \, dx = 0 \text{ for all } n\geq0, \text{ then } f = 0$$
Since $f$ is continous on a closed interval, then by stone Aproximation Theoren , for each $\epsilon > 0$ , there is a polynomial $p(x)$ such that $|f(x) - p(x)| < \epsilon$.
I want to show that $\int_0^\pi f(x) \, dx = 0$,  please help me how to proceed further and check the first part. Any help would be appreciated.
 A: I am usually too lazy to critique answers even when the OP asks for it. It is easier to just snipe
with a comment or two. But @zhw has shamed me into really looking at the answer and maybe offering 
a bit of a tutorial.  Since I gave a sloppy comment I will make amends here I hope.
Here some things that you know or should know judging from the title of the problem and your answer.


*

*A continuous   even function $f$ on $[-\pi,\pi]$ has a Fourier series of the form
$$\sum_{n=0}^\infty a_n\cos nx$$ but this series need not converge pointwise or uniformly to $f$ unless you have
stronger assumptions on $f$. [Here you don't. A course on Fourier series may not prove this negative comment, just proving the positive comment assuming, say, that $f$ is also of bounded variation or continuously differentiable.  It is essential to know why 19th century mathematicians had to fuss so much to get convergence.]

*A continuous   even function $f$ on $[-\pi,\pi]$ has a uniform approximation
by a trigonometric polynomial 
of the form
$$\sum_{n=0}^N a_n\cos nx$$ meaning that, for every $\epsilon>0$ you can select at least one such polynomial so that
$$\left| \sum_{n=0}^N a_n\cos nx -f(x)\right| < \epsilon$$
for all $-\pi\leq x \leq \pi$. [Fejer's theorem supplies this as does the Stone-Weierstrass theorem.]

*[Dangerous curve ahead!]  If you change $\epsilon$ you may have to choose an entirely different polynomial, so the $a_n$ might change.  Thus statement #2 does not give you a series converging to $f$, it gives you a sequence of trigonometric polynomials converging uniformly to $f$.  In other words Stone-Weierstrass or Fejer's theorem does not give
$$f(x)=\sum_{n=0}^\infty a_n\cos nx$$ 
either pointwise or uniformly.  Don't write it!

*If $f(x)=\sum_{i=0}^\infty f_n(x)$ on $[a,b]$ you cannot write  $\int_a^b f   =\sum_{i=0}^\infty \int_a^b f_n $ without claiming uniform convergence (or some more advanced property).  

*If $f(x)=\lim_{n\to \infty} f_n(x)$ on $[a,b]$ you can  write  $$\int_a^b fh   =\lim_{n\to \infty}   \int_a^b f_nh $$ 
for any continuous $h$ 
if you are sure you have uniform convergence (or some more advanced property).  
Now we are in a position to tidy up your solution.  Your ideas were fine, just missing some caution.  You tried to use a series but that fails--just use a sequence instead!
For the first problem use Stone-Weierstrass to select an appropriate sequence of functions $p_n \to f$ uniformly on $[-\pi,\pi]$. Check that
$$\int_{-\pi}^\pi f(x)p_n(x)\,dx =0$$
for each $n$ and that
$$\lim_{n\to \infty}  \int_{-\pi}^\pi f(x)p_n(x)\,dx =\int_{-\pi}^\pi [f(x)]^2\,dx.$$
Conclude that $f=0$ since it is continuous. 
For the second problem use Stone-Weierstrass to select an appropriate sequence of functions $p_n \to f$ uniformly on $[0,1]$. Check that
   $$\int_{0}^1 f(x)p_n(x)\,dx =0$$
   for each $n$ and that
   $$\lim_{n\to \infty}  \int_{0}^1 f(x)p_n(x)\,dx =\int_{0}^1 [f(x)]^2\,dx.$$
   Conclude that $f=0$ since it is continuous. 
A: Proceeding as you started.
$g$ is an even function. Hence all the sine part of its Fourier transform is equal to $0$. By hypothesis, the cosine part is also equal to $0$ as it is the case for $f$.
Finally, the Fourier transform of $g$ is equal to $0$. As $g$ is continuous, $g$ is always vanishing and consequently, $f$ vanishes on $[0,\pi]$.
A: ON the other hand, using the result for the second part we can demostrate the first one.


Lemma 1. For each $n\in \mathbb{N}$, $\cos(nx)$ is a polynomial on $\cos x$
Proof: Apply induction.


Now, let $S=\{p\circ\cos\, |\, p\mbox{ is a polynomial} \}$.


Lemma 2: The set $S$ is dense in $C[0,\pi]$ with the norm $\|\cdot\|_{\infty}$.
Proof: Let $f\in C[0,\pi]$ and $\epsilon>0$. Note that $\arccos:[-1,1]\to[0,\pi]$ is well defined and continous. Then, $f\circ \arccos\in C[-1,1]$.
By Stone-Weierstrass, there is a polynomial $p\in C[-1,1]$ such that $|p(y)-f(\arccos(y))|<\epsilon$ for all $y\in[-1,1]$.
Then, if $x\in[0,\pi]$, we can take $y\in[-1,1]$ such that $y=\cos(x)$. Thus $\epsilon>|p(\cos(x))-f(x)|$ for arbitrary $x\in[0,\pi]$. That is $\|f\circ \cos-f\|_\infty<\epsilon$, so the lemma holds.


Lemma 3: If A is dense in $C[0,\pi]$ and there is a $f\in C[0,\pi]$ such that $\int_0^\pi f(x)g(x)dx=0$, then $f(x)=0$ for all $x$.
Proof: Basically the proof is an abstract version of the proof that I gave for the second part of your original question.


Then, for your problem, by means of hypothesis about $\cos nx$ it can be show that $\int_0^\pi f(x)p(\cos(x))dx=0$ for all polynomials $p$. But, this familie is dense by Lemma 2. Then, by Lemma 3 we get the desired conclusion. 
A: For the second part, supose $f\neq 0$. Then $\|f\|\neq0$. Thus, for any $\epsilon>0$ there is a polynomial $p(x)$ such that $|f(x)-p(x)|<\dfrac{\epsilon}{2\pi\|f\|_{\infty}}$.
Then 
$\begin{eqnarray}
\int_0^\pi f^2(x)dx&=&\int_0^\pi f(x)f(x)dx\\
&=&\int_0^\pi f(x)(f(x)-p(x)+p(x))dx\\
&=&\int_0^\pi f(x)(f(x)-p(x))dx+\int_0^\pi f(x)p(x)dx\\
&=&\int_0^\pi f(x)(f(x)-p(x))dx\mbox{ by hypothesis}\\
&\le&\int_0^\pi |f(x)(f(x)-p(x))|dx\\
&\le&\|f\|_\infty\int_0^\pi |f(x)-p(x)|dx\\
&\le&\|f\|_{\infty}\int_0^\pi \dfrac{\epsilon}{2\pi\|f\|_{\infty}}dx\\
&=&\frac{\epsilon}{2}\\
&<&\epsilon
\end{eqnarray}$
That is $\int_0^\pi f^2(x)dx<\epsilon$ for all $\epsilon$. Then $f^2(x)=0$, and finally $f(x)=0$. But this contradicts that $f\neq 0$.
