# Mathematica is failing the computation of $\int_0^{2\pi}\left(\sum_{k=0}^n\cos(k x)\right)\mathrm dx$

I tried to compute

$$\int_0^{2\pi}\left(\sum_{k=0}^n\cos(k x)\right)\mathrm dx$$

with two different codes:

Integrate[Sum[Cos[k*x],{k,0,n}],{x,0,2*Pi},Assumptions->n\[Element]Integers && n>0]


and

Refine[Integrate[Sum[Cos[k*x],{k,0,n}],{x,0,2*Pi}],n\[Element]Integers && n>0]


but both failed. However if I make a table of values for n then the computation works normally. There is a way to fix this behavior?

Sum[Integrate[Cos[k*x], {x, 0, 2*Pi}], {k, 0, n}]

$2 \pi$
• I dont knew that changing the order it can fix this behavior, thank you. Probably what happens is that mathematica dont know that k is a natural number for the other computation order. – Masacroso Apr 3 '17 at 10:47