If $ \int_0^{\pi}f(x)\cos(nx)\,dx=0$ for all $n$ then prove that $f\equiv 0$

Extend $f$ to be even on $[-\pi,\pi].$ We then have

$$\hat f (n) = \frac{1}{2\pi}\int_{-\pi}^\pi f(x)e^{-inx}\,dx = \frac{1}{\pi}\int_{0}^\pi f(x)\cos (nx)\,dx = 0$$

for all $n\in \mathbb {Z}.$ Thus $$\frac{1}{2\pi}\int_{-\pi}^\pi|f|^2 = \sum |\hat f (n)|^2 = 0.$$

This implies $f\equiv 0.$ I did not use the condition $f(0)=0,$ which makes me think the problem should have been stated assuming $\int_0^\pi f(x)\sin (nx)\, dx =0, n=1,2,\dots.$


You can extend $f$ to $g$ on $[-\pi,\pi]$, s.t. $g(x)=f(-x)$ if $x<0$. Then $\hat{g}(n)=\frac{1}{\pi}\int_0^\pi f(x)cos(nx)dx=0$ for all $n$. By Parseval's identity, $\int |g|^2=0$ which implies $f=0$.


(Complete revamp of my previous answer.)

Extend $f$ by $f(x) = f(-x)$ for $x \in [-\pi,0)$, then $f$ is $2\pi$ periodic and so for any $\epsilon>0$ there is a trigonometric polynomial $q$ such that $\|f-q\|_\infty = \sup_{|x|\le \pi} |f(x)-q(x)| < \epsilon$. (Recall that a trigonometric polynomial is of the form $q(t) = a_0+\sum_{k=1}^n (a_k \cos(kt) + b_k \sin (kt))$). (See, for example, Rudin's "Real & Complex Analysis", Theorem 4.25.)

Let $\tilde{q}(t) = {1 \over 2} (q(t)+q(-t))$ and note that $\|f-\tilde{q}\|_\infty \le {1 \over 2} (\|f-q\|+ \|f-q\|) < \epsilon$ (where we used evenness of $f$ for the last part). Hence we may assume that $q$ is even to begin with, in particular, $q$ has the form $q(t) = a_0+\sum_{k=1}^n a_k \cos(kt) = \sum_{k=0}^n a_k \cos(kt)$.

Note that, by assumption, $\int_{-\pi}^\pi f(x) q(x) dx = 0$.

Then $\int_{-\pi}^\pi f^2(x) dx = \int_{-\pi}^\pi f(x) (f(x)-q(x)+ q(x)) dx = \int_{-\pi}^\pi f(x) (f(x)-q(x)) dx$, hence $\int_{-\pi}^\pi f^2(x) dx \le \|f\|_\infty 2 \pi \epsilon$. Since $\epsilon>0$ was arbitrary, we see that $\int_{-\pi}^\pi f^2(x) dx = 0$. Since $f$ is continuous, and $f^2(x) \ge 0$ for all $x$ we see that $f(x) = 0$ for all $x$.