5

How to simplify my expression to the style of "a+b*I"?

Expand[(E^(I θ) (-1 + E^(I n θ)))/(-1 + E^(I θ))]
-(E^(I θ)/(-1 + E^(I θ))) + E^(I θ + I n θ)/(-1 + E^(I θ))

the result I want to achieve

Kuba
  • 136,707
  • 13
  • 279
  • 740

3 Answers3

3

I hope this is what you need:

Collect[Expand[(E^(I \[Theta]) (-1 + E^(I n \[Theta])))/(-1 + 
      E^(I \[Theta]))] // ComplexExpand, I]

enter image description here

faleichik
  • 12,651
  • 8
  • 43
  • 62
3

As shown by others, you are looking for a combination of ComplexExpand and Collect. In your case, ComplexExpand does a good job of separating the real and imaginary components of your expression.

enter image description here

In general, you will end up with a number of terms, and you will need to use Collect to merge them together. However, using Collect on I does not usually work

Collect[a I + (1 + I) b, I]
(* I a + (1 + I) b *)

because I is interpreted as Complex[0, 1], so Collect will not break up numbers like 1 + I. So, the most effective method I have found is to replace I with some other symbol, like q.

Block[{q}, 
  Collect[
   ComplexExpand[expr] /. Complex[a_, b_] :> a + q b, 
   q, Simplify
  ] /. q -> I
]
(*
    Cos[1/2 (1 + n) θ] Csc[θ/2] Sin[(n θ)/2] 
+ I Csc[θ/2] Sin[(n θ)/2] Sin[1/2 (1 + n) θ]
*)

where expr is your expression. Note I set the third argument of Collect to Simplify which reduced the complexity of the real and imaginary parts quite well.

rcollyer
  • 33,976
  • 7
  • 92
  • 191
2
exp = Expand[(E^(I \[Theta]) (-1 + E^(I n \[Theta])))/(-1 +E^(I \[Theta]))]

Mathematica graphics

r = Simplify@ComplexExpand@Re@exp + I*Simplify@ComplexExpand@Im@exp

Mathematica graphics

it is now in the form a+I b

{a, b} = First@Cases[r, Plus[a_, I b_] :> {a, b}, {0}];
a

Mathematica graphics

b

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359