TITLE: Prove that $\int_{0}^{2\pi}f(x)\cos(kx)dx \geq 0$ for every $k \geq 1$ given that $f$ is convex.
QUESTION [8 upvotes]: Given $f: [0, 2\pi] \to \mathbb{R}$ convex function, prove that for every $k\geq1$
\begin{align}
\int_{0}^{2\pi}f(x) \cos (kx)dx \geq 0
\end{align}
I am completely stumped. What I have tried to do is return the query for $k=1$, and for that value of $k$ try to write the integral from $0$ to $2\pi$ as a sum of four integrals from $0$ to $\dfrac{\pi}{2}$ and use the the theorem for first derivative monotony. No luck so far.
Any help would be much appreciated.
Edit 1: I saw the link here about a similarly asked topic. However, this process gets the general case as I perceive it and I am really supposed to use the method described above. I will try this and come back with a definitive answer.
Edit 2: I cannot use the $f''(x) \geq 0$ argument due to the simple fact that I have not been formally taught it as part of the class.
Edit 3: Final proof, with thanks to the contributors below.
Let's start by setting $A = \frac{\pi}{2}$ and $B = \frac{3\pi}{2}$. It follows from basic trigonometry that:
\begin{align}
&\cos x \geq 0, \ x \in [A,B] \ \text{and}\\
&\cos x \leq 0, \ x \in [0, A] \cap [B, 2\pi].
\end{align}
And we also set $L$ to be the line segment such that $L(A) = f(A), \ L(B) = f(B)$. We will prove a basic property of said line in regards to the convex function $f$.

I can take for granted that (we proved this in class)
\begin{align}
L(x) = \dfrac{x-A}{B-A}f(B) + \dfrac{B-x}{B-A}f(A)
\end{align}
so for $x \in [A,B]$ there exists $\lambda \in [0,1]$ such that: $x = \lambda A + (1-\lambda) B$. Taking the aforementioned expression and replacing it on $L(x)$ we get (I omit trivial algebra)
\begin{align}
L(x) = (1-\lambda) f(B) + \lambda f(A).
\end{align}
Since $f$ is convex, we can write
\begin{align}
&f(\lambda A + (1-\lambda) B) \leq \lambda f(A) + (1-\lambda) f(B)\\
\implies &f(x) \leq L(x), \ \forall \ x \in [A,B] \ \text{and} \ \lambda \in [0,1].
\end{align} $\blacksquare$

We assume that there exists $x \in [0,A]: \ f(x) < L(x)$. Then there exists $A \in [x, B] \ \text{and} \ \lambda \in [0,1]: \ A = \lambda x + (1-\lambda) B$. Then
\begin{align}
&L(A) = \dfrac{A-x}{B-x}f(B) + \dfrac{B-A}{B-x}f(x), \ A \in [x,B]\\
\implies &L(A) = (1-\lambda)L(B)+\lambda L(x)\\
\implies &L(A) = (1-\lambda)f(B) + \lambda L(x).
\end{align}
Then assuming that $L(x) > f(x)$ we get
\begin{align}
L(A) > (1-\lambda) f(B) + \lambda f(x) \geq f(A), \ \text{assuming convexity}.
\end{align}
Because $L(A) = f(A)$ the above inequality becomes $L(A) > f(A)$ which is a contradiction.


$\blacksquare$
In the same spirit, for $x \in [B, 2\pi]$ doing the exact same replacements and applying the exact same principles we also get
\begin{align}
&f(\lambda B + (1-\lambda) 2 \pi) \leq \lambda f(B) + (1-\lambda) f(2\pi)\\
\implies &f(x) \leq L(x).
\end{align}
$\blacksquare$
We then set $g(x) = f(x) - L(x)$ and from (1) and (2) above it is safe to assume that $\cos x$ and $g(x)$ will have the same sign in the whole domain, that is:
\begin{align}
&g(x) \geq 0, \ \text{where} \ \cos x \geq 0\\
&g(x) \leq 0, \ \text{where} \ \cos x \geq 0.
\end{align}

We have
\begin{align}
\int_0^{2\pi} g(x) \cos x dx = \int_0^{\frac{\pi}{2}} g(x) \cos x dx + \int_{\frac{\pi}{2}}^{\frac{3 \pi}{2}} g(x) \cos x dx + \int_{\frac{3\pi}{2}}^{2\pi}g(x) \cos x dx \geq 0,
\end{align}
because
\begin{align}
&\text{in} \left[0, \frac{\pi}{2} \right], \ \cos x \geq 0 \implies g(x) \geq 0\\
&\text{in} \left[\frac{\pi}{2}, \frac{3 \pi}{2} \right], \ \cos x \leq 0 \implies g(x) \leq 0\\
&\text{in} \left[\frac{3 \pi}{2}, 2 \pi \right], \ \cos x \geq 0 \implies g(x) \geq 0.\\
\end{align}

We have that
\begin{align}
&\int_0^{2 \pi}\cos x dx = 0 \ \text{trivial}\\
&\int_0^{2 \pi}x \cos x dx = \int_0^{2 \pi}x (\sin x)' dx = \left[ x \sin x \right]_0^{2\pi} - \int_0^{2 \pi} \sin x dx = 0.
\end{align}


It then follows that
\begin{align}
\int_0^{2 \pi} f(x) \cos x dx = \int_0^{2 \pi} g(x) \cos x dx \geq 0
\end{align}
which was previously proven. For the case $k=1$, the proof is over.
For $k>1$, we have:
\begin{align}
\int_0^{2\pi}f(x) \cos (kx) dx = \sum_{i=0}^{k-1} \int_{\frac{2\pi i}{k}}^{\frac{2\pi (i+1)}{k}} f(x) \cos (kx) dx.
\end{align}
We perform the change of variable
\begin{align}
x = \dfrac{y+2\pi i}{k}\\
\implies \begin{cases}dx = \dfrac{1}{k}dy\\ x = \dfrac{2\pi i}{k} \to y=0\\ x = \dfrac{2\pi (i+1)}{k} \to y = 2\pi \end{cases}.
\end{align}
So the above sum becomes
\begin{align}
\sum_{i=0}^{k-1} \dfrac{1}{k} \int_{0}^{2\pi}f \left(\dfrac{y+2 \pi i}{k} \right) \cos (y+2\pi i)dy.
\end{align}
Because $f$ is convex in $[0, 2\pi]$ there exists $\lambda \in [0,1]$ such that:
\begin{align}
 \theta f\left(\frac{y_1 + 2\pi i}{k}\right)
 + (1 - \theta)f\left(\frac{y_2 + 2\pi i}{k}\right)
 &\ge f\left(\theta\frac{y_1 + 2\pi i}{k}
 + (1 - \theta) \frac{y_2 + 2\pi i}{k}\right)\\
 &= f\left(\frac{\theta y_1 + (1 - \theta)y_2 + 2\pi i}{k}\right).
\end{align}
Having performed the change of variables:
\begin{align}
x_1 = \dfrac{y_1 + 2\pi i}{k} \ \text{and} \ x_2 = \dfrac{y_2 + 2\pi i}{k}.
\end{align}
So $f \left( \dfrac{y + 2\pi i}{k}\right)$ convex on $[0, 2\pi]$. Using the result from $k=1$ we have
\begin{align}
\int_0^{2\pi} f \left( \dfrac{y + 2\pi i}{k} \right)\cos y dy \geq 0.
\end{align}
$\blacksquare$

REPLY [3 votes]: As demonstrated in the other answers, it suffices to prove the statement for $k=1$, that is
$$
 I = \int_{0}^{2\pi}f(x) \cos (x) \, dx \ge 0 \, .
$$
We can split the integral into four parts over the intervals $[0, \pi/2]$, $\pi/2, \pi]$, $[\pi , 3\pi/2]$ and $[3\pi/2, 2 \pi|$ and substitute $x = \pi - y$, $x=\pi + y$, $x =2\pi -y$ in the second, third, and fourth integral, respectively. This gives
$$
 I = \int_0^{\pi/2} \bigl( f(x) - f(\pi -x) - f(\pi + x) + f(2\pi - x)\bigr) \cos(x) \, dx \, .
$$
So order to prove $I \ge 0$ it suffices to show that
$$ \tag{$*$}
f(\pi -x) + f(\pi + x) \le f(x) + f(2\pi - x) 
$$
for $0 \le x \le \pi/2$.
And that follows directly from the convexity condition, applied to $x < \pi - x< 2 \pi-x$:
$$
 f(\pi - x) \le \frac{\pi}{2 \pi - 2x}f(x) + \frac{\pi - 2x}{2 \pi - 2x}f(2\pi - x) \, ,
$$
and to $x < \pi + x < 2 \pi-x$:
$$
 f(\pi + x) \le \frac{\pi-2x}{2 \pi - 2x}f(x) + \frac{\pi}{2 \pi - 2x}f(2\pi - x) \, .
$$
Adding these two inequalities gives exactly $(*)$, and that finishes the proof.