1
$\begingroup$
Collect[Expand[(x + I y)^6], I]

yields

x^6 + 6 I x^5 y - 15 x^4 y^2 - 20 I x^3 y^3 + 15 x^2 y^4 + 6 I x y^5 - y^6

How can I obtain

x^6 - 15 x^4 y^2 + 15 x^2 y^4 - y^6 + (6 x^5 y - 20 x^3 y^3 + 6 x y^5) I 
$\endgroup$

1 Answer 1

6
$\begingroup$
ComplexExpand[(x + I y)^6]
x^6 - 15 x^4 y^2 + 15 x^2 y^4 - y^6 + I (6 x^5 y - 20 x^3 y^3 + 6 x y^5)

Collect is not especially designed for your purpose. Nonetheless if one insists on using it we can take e.g. ComplexExpand for the third argument in Collect to get the former result (Expand is not needed anymore):

Collect[ (x + I y)^6, I, ComplexExpand]

In case that you'd like to get the result in the form a I instead of I a, I'd use a simple replacement rule I a_ :> HoldForm[a I], e.g.

ComplexExpand[(x + I y)^6] /. I a_ :> HoldForm[a I]
x^6 - 15 x^4 y^2 + 15 x^2 y^4 - y^6 + (6 x^5 y - 20 x^3 y^3 + 6 x y^5) I
$\endgroup$
3
  • $\begingroup$ I am not committed to Collect. If you know of a more appropriate solution, please share it. $\endgroup$ Commented Jul 14, 2013 at 23:23
  • $\begingroup$ @PhillipDukes ComplexExpand is an appropriate solution. You can take a look at its options (TargetFunctions) if there might be some specific needs for customizing the output form. In general it is difficult to guess what kind of results one expects if not provided more specific example. If you doubt about ComplexExpand universality, please provide an example where it doesn't work as you expect. I'll try to help anyway. $\endgroup$
    – Artes
    Commented Jul 14, 2013 at 23:49
  • $\begingroup$ @Artes how do you Collect this example (1 - I) (c (1 + I) + d) $\endgroup$
    – Rainb
    Commented May 9, 2021 at 12:55

Your Answer

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

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