6
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Raksha
    Mar 18, 2015 at 3:15

1 Answer 1

5
$\begingroup$

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

enter image description here

Case 1, Re outside, ComplexExpand inside

 Simplify@Re@ComplexExpand@exp

Mathematica graphics

Case 2, Re inside, Expand outside

 Simplify@Expand@Re@exp

Mathematica graphics

Case 3, Re inside, ComplexExpand outside

 Simplify@ComplexExpand@Re@exp

Mathematica graphics

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.