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$
 A: I will try to give you some hints that can give you a proof using essentially only the definition of convexity.
Start by the case $k=1$. Denote $A=\pi/2$, $B=3\pi/2$, so that $\cos x\geq 0$ in $[A, B]$ and $\cos x\leq 0$ in $[0,A]\cap[B,2\pi]$. Let $L$ be the straight line such that $L(A)=f(A)$ and $L(B)=f(B)$.

*

*Show that $f(x)\leq L(x)$ for all $x\in[A, B]$. (Hint: just apply the definition of convexity...)


*Show that $f(x)\geq L(x)$ in $[0,A]\cap[B,2\pi]$. (Hint: assume that there is a point $x$ such that this is not true and try to find the contradiction...)
Now we can consider the function $g = f-L$. From the points (1) and (2) you have that, on $[0,2\pi]$, $g\geq 0$ where $\cos\geq 0$ and $g\leq 0$ where $\cos\leq 0$.


*Conclude that $\int_0^{2\pi}g(x)\cos x dx\geq 0$.


*Show that $\int_0^{2\pi}f(x)\cos x dx=\int_0^{2\pi}g(x)\cos x dx$. (Hint: first show that $\int_0^{2\pi}\cos x dx=0$ and $\int_0^{2\pi}x\cos x dx=0$...)
Now you need to consider the generic case $k\geq 1$. However this follows from the case $k=1$. The idea is that we can split $[0, 2\pi]$ in $k$ intervals of length $2\pi/k$. Now let $[a, b]$ be one of this intervals, that is for some integer $0\leq m<k$ you have $ak=2m\pi$ and $bk=2(m+1)\pi$. We need to show that $\int_a^b \cos(kx)f(x)dx\geq 0$.


*Show that $\int_a^b \cos(kx)f(x)dx = \frac{1}{k}\int_0^{2\pi}f\left(a+x/k\right)\cos(x)dx$. (Hint: this is just a change of variable...)


*Show that $x\mapsto f\left(a+x/k\right)$ is convex and conclude that $\int_a^b \cos(kx)f(x)dx\geq 0$.


*Show that $\int_0^{2\pi}f(x)\cos(kx)dx\geq 0$.
I hope that this will help you.
A: The proof using twice integration by parts requires differentiability of $f.$ Instead we can use summation by parts as follows. The integral in question is the limit of Riemann sums
$$S_n:={1\over n}\sum_{j=1}^n f\left ({2\pi j\over n}\right )\cos {2\pi k j\over n}$$ It  suffices to show that $\lim S_n\ge 0.$
Observe that $$2\sin{\pi k \over n}\cos{2\pi kj\over n}=\sin {2\pi k(j+{1\over 2}) \over n}-\sin {2\pi k(j-{1\over 2}) \over n}$$
Therefore denoting $a_j=f\left ({2\pi j\over n}\right )$ and
$b_j=\sin {2\pi k(j+{1\over 2}) \over n}$
leads to
$$2n\sin\ {\pi k \over n}\ S_n=\sum_{j=1}^n a_j(b_j-b_{j-1})
=\sum_{j=0}^{n-1} (a_j-a_{j+1})b_j +a_{n}b_n-a_0b_0\\
=\sum_{j=0}^{n-1} (a_j-a_{j+1})b_j+[f(1)-f(0)]\,\sin{\pi k\over n}
$$
We have
$$ 2\sin {\pi k \over n}\cdot b_j=\left [1-\cos{2\pi k (j+1)\over n}\right ]-\left [1-\cos{2\pi k j\over n}\right ]$$
Hence denoting $\Delta a_j=a_j-a_{j+1},$ $c_j=1-\cos{2\pi k j\over n}$  and observing that $c_0=c_n=0$ gives
$$ 4n\sin^2{\pi k\over n} \ S_n= \sum_{j=0}^{n-1}\Delta a_j\,[c_{j+1}-c_{j}]+ 2[f(1)-f(0)]\,\sin^2{\pi k\over n}\\
= \sum_{j=1}^{n-1} [\Delta a_{j-1}-\Delta a_j]c_j+\Delta a_{n-1}\,c_n-\Delta a_0\,c_0 +  2[f(1)-f(0)]\,\sin^2{\pi k\over n}\\
= \sum_{j=1}^{n-1} [\Delta a_{j-1}-\Delta a_j]c_j+ 2[f(1)-f(0)]\,\sin^2{\pi k\over n}$$
Summarizing
$$S_n={1\over 4n\sin^2{\pi k\over n}} \sum_{j=1}^{n-1} [\Delta a_{j-1}-\Delta a_j]c_j+{1\over 2n}[f(1)-f(0)]$$
The sum is nonnegative as $c_j\ge 0$ and $\Delta a_{j-1}-\Delta a_j=a_{j-1}+a_{j+1}-2a_j\ge 0$, by the convexity of $f$.  Hence  $\lim S_n$ is nonnegative.
A: 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.
A: 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.
A: Without loss of generality we may assume that $f$ is twice continuously differentiable on $[0,2\pi].$ Then
$$ \int_0^{2\pi}f(x)\cos(kx)\,dx=\left. f(x)\frac {\sin(kx)} k\right |_0^{2\pi} -\int_0^{2\pi} f'(x)\frac {\sin(kx)} k\,dx= -\int_0^{2\pi} f'(x) \frac {\sin(kx)} k\,dx.$$
Next, again integraiting by parts, this equals
$$\left. f'(x)\frac {\cos(kx)} k\right|_0^{2\pi} - \int_0^{2\pi}f''(x)\cos(kx)\,dx\ge$$ $$f'(2\pi)-f'(1)-\int_0^{2\pi}f''(x)\cdot1\,dx= $$ $$f'(2\pi)-f'(1)-\int_0^{2\pi} f''(x)\,dx=0 $$ since the second derivative of a convex function is nonnegative. The general case is obtained by approximation of $f(x)$ by a smooth function with precision  $\epsilon$, making use of convolution, and then by taking the limit as $\epsilon\to 0+$.
