Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
I'm sorry, this is completely random, but I didn't want to start another question and it appears there is no way to contact users here directly. I was wondering if you could please tell me how you copy-pasted your code so it looks so nice. – Solarmew Mar 18 at 3:15

1 Answer 1

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}]]

Mathematica graphics

Case 1, Re outside, ComplexExpand inside


Mathematica graphics

Case 2, Re inside, Expand outside


Mathematica graphics

Case 3, Re inside, ComplexExpand outside


Mathematica graphics

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.