Prove that $\int_{0}^{2\pi}f(x)\cos(kx)dx \geq 0$ for every $k \geq 1$ given that $f$ is convex. 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$

Complement to @ECL's answer:

*

*For $k = 1$:

Let
$$g(x) := f(x) - \frac{f(3\pi/2) - f(\pi/2)}{\pi}x - \frac{\frac{3\pi}{2}f(\pi/2) - \frac{\pi}{2}f(3\pi/2)}{\pi}.$$
We have $g(\pi/2) = g(3\pi/2) = 0$.
Also, $g(x)$ is convex on $[0, 2\pi]$.
For $x \in [\pi/2, 3\pi/2]$, letting $t = \frac{3}{2} - \frac{x}{\pi} \in [0, 1]$, we have $x = \frac{\pi}{2} t 
+ \frac{3\pi}{2}(1 - t)$ and
$$g(x) \le t g(\pi/2) + (1 - t)g(3\pi/2)  = 0.$$
For $x\in [0, \pi/2]$, using $\pi - x \in [\pi/2, 3\pi/2]$ and $g(x) + g(\pi - x) \ge 2g(\pi/2) = 0$, we have
$$g(x) \ge -g(\pi - x) \ge 0.$$
For $x\in [3\pi/2, 2\pi]$, using $3\pi - x\in [\pi/2, 3\pi/2]$ and $g(x) + g(3\pi - x) \ge 2g(3\pi/2) = 0$, we have
$$g(x) \ge -g(3\pi - x) \ge 0.$$
Using $\int_0^{2\pi} \cos x \mathrm{d} x = 0$ and $\int_0^{2\pi} x \cos x \mathrm{d} x = 0$, we have
\begin{align*}
 &\int_0^{2\pi} f(x) \cos x \mathrm{d} x\\
 =\,& \int_0^{2\pi} g(x)\cos x \mathrm{d} x\\
 =\,& \int_0^{\pi/2} g(x)\cos x \mathrm{d} x
 + \int_{\pi/2}^{3\pi/2} g(x)\cos x \mathrm{d} x
 + \int_{3\pi/2}^{2\pi} g(x)\cos x \mathrm{d} x\\
  \ge\,& 0.
\end{align*}
$\phantom{2}$


*For $k > 1$:

We have
\begin{align*}
 &\int_0^{2\pi} f(x)\cos k x \mathrm{d} x\\
 =\,& \sum_{i=0}^{k-1} \int_{2\pi i/k}^{2\pi(i + 1)/k} f(x)\cos k x \,\mathrm{d} x\\
 =\,& \sum_{i=0}^{k-1} \frac{1}{k}\int_0^{2\pi} f\left(\frac{y + 2\pi i}{k}\right)\cos y\, \mathrm{d} y.
\end{align*}
For any $y_1, y_2 \in [0, 2\pi]$ and $\theta \in [0, 1]$, we have
\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*}
Thus, $f\left(\frac{y + 2\pi i}{k}\right)$ is convex on $[0, 2\pi]$.
Using the result for $k = 1$, we have
$$\int_0^{2\pi} f\left(\frac{y + 2\pi i}{k}\right)\cos y \,\mathrm{d} y \ge 0.$$
The desired result follows.
