Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to convert a list of $n$ complex equations to a list of $2n$ real ones. At the moment I am doing it like this:

eqs = {a + I b == 0, c + I d == 0}
Flatten[{ComplexExpand[Re[First[#]]] == 0 & /@ eqs,  
         ComplexExpand[Im[First[#]]] == 0 & /@ eqs}] 

I would like to know how I can write this more compactly, since I'm basically using the same command twice, with the only difference being changing the function Re -> Im. Perhaps I can use a pure function to map over a list of these 2 functions?

Thanks!

share|improve this question
1  
Equal[#, 0] & /@ {Re@#, Im@#} & /@ First /@ eqs –  belisarius Jan 8 '13 at 18:52
1  
@belisarius you forgot ComplexExpand. –  Mr.Wizard Jan 8 '13 at 22:33
2  
@Mr.Wizard One more item for the list I'm sowing thru my life –  belisarius Jan 8 '13 at 22:35

3 Answers 3

up vote 1 down vote accepted

I would probably do something like this:

eqs = {a + I b == 0, c + I d == 0};

Join @@ Thread /@ ComplexExpand @ Map[{Re@#, Im@#} &, eqs, {2}]
{a == 0, b == 0, c == 0, d == 0}

Or shorter:

Join @@ ComplexExpand[Map[#, eqs, {2}] & /@ {Re, Im}]
{a == 0, c == 0, b == 0, d == 0}

The order is slightly different, if it matters.

share|improve this answer
    
Thanks, works like a charm ;) –  Andrei Jan 9 '13 at 16:39

This seems like a good place for Through, since it can take multiple functions (like Im and Re) and apply them to the same arguments, so for example,

Through[{Re, Im}[a + b I]]

{-Im[b] + Re[a], Im[a] + Re[b]}

For the specific problem at hand, this can be done

eqs = {a + I b == 0, c + I d == 0};
Join@@Thread/@(ComplexExpand@Through[{Re, Im}[First[#]]] == {0, 0} & /@ eqs)

{a == 0, b == 0, c == 0, d == 0}
share|improve this answer

Using Outer:

eqs = {a + I b == 0, c + I d == 0};
Flatten@Outer[
  ComplexExpand[#1[#2]] == 0 &,
  {Re, Im}, {First /@ eqs}]

Might have to specify the level in the general case.

share|improve this answer

Your Answer

 
discard

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.