Tell me more ×
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 at 18:52
@belisarius you forgot ComplexExpand. – Mr.Wizard Jan 8 at 22:33
2  
@Mr.Wizard One more item for the list I'm sowing thru my life – belisarius Jan 8 at 22:35

1 Answer

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 at 16:39

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.