# Simplifying a trigonometric sum

I want to caculate Cos[θ] + Cos[2 θ]+ ... + Cos[n θ]

Sum[Cos[k θ], {k, 1, n}]
Cos[1/2 (1 + n) θ] Csc[θ/2] Sin[(n θ)/2]

But when I use Euler's formula

Re[Expand[ExpToTrig[Sum[E^(I k θ), {k, 1, n}]]]]

I get

Im[Sin[θ]/(-1 + Cos[θ] + I Sin[θ])] -
Im[(Cos[n θ] Sin[θ])/(-1 + Cos[θ] + I Sin[θ])] -
Im[(Cos[θ] Sin[n θ])/(-1 + Cos[θ] + I Sin[θ])] +
Re[-(Cos[θ]/(-1 + Cos[θ] + I Sin[θ])) +
(Cos[θ] Cos[n θ])/(-1 + Cos[θ] + I Sin[θ]) -
(Sin[θ] Sin[n θ])/(-1 + Cos[θ] + I Sin[θ])]

Why doesn't Mathmatica simplify it?

-

The rule of thumb that I use is this: Put Re as close as possible to the expression that I want to obtain its real (or imaginary) part and then put the result inside ComplexExpand and not Expand. (same applied to Im).

ComplexExpand assumes variables in expression are all real, and hence can do more simplification than Expand.

So the pattern is Simplify[ ComplexExpand [ Re [ .... ] ] ]

Compare the following 3 cases, all using the same expression to start with:

exp = ExpToTrig[Sum[E^(I k \[Theta]), {k, 1, n}]]

## Case 1, Re outside, ComplexExpand inside

Simplify@Re@ComplexExpand@exp

## Case 2, Re inside, Expand outside

Simplify@Expand@Re@exp

## Case 3, Re inside, ComplexExpand outside

Simplify@ComplexExpand@Re@exp

-
I like your answer, but where did the x y^2 come from? Did you have some uncleared variable assignments? –  m_goldberg Sep 12 '13 at 9:43
@m_goldberg I was doing my HW's in the other side :(, must have sneeked in without my noticing. Will fix now –  Nasser Sep 12 '13 at 9:50