MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to collect terms based the total power of x and y

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92195] Re: [mg92158] How to collect terms based the total power of x and y
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 22 Sep 2008 07:26:08 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

expr = 1 + 3 x + 3 x^2 + x^3 + 3 y + 6 x y + 3 x^2 y + 3 y^2 + 
  3 x y^2 + y^3

x^3+3 y x^2+3 x^2+3 y^2 x+6 y x+3 x+y^3+3 y^2+3 y+1

List @@ Collect[expr /. {x -> x*z, y -> y*z}, z] /. z -> 1

{1,3 x+3 y,3 x^2+6 y x+3 y^2,x^3+3 y x^2+3 y^2 x+y^3}

expr == Total[%] == Plus @@ %

True


Bob Hanlon

---- Peng Yu <PengYu.UT at gmail.com> wrote: 

=============
Hi,

In[(x + y + 1)^3 // Expand

The above command gives me the following results.

1 + 3 x + 3 x^2 + x^3 + 3 y + 6 x y + 3 x^2 y + 3 y^2 + 3 x y^2 + y^3

I'm wondering how to collect terms based on the sum of the power
coefficients of both x and y. For example, I want the following

1 + (3 x + 3 y) + (3 x^2 + 6 x y + 3 y^2) + (x^3 + 3 x^2 y + 3 x y^2 +
y^3)

Thanks,
Peng


--

Bob Hanlon



  • Prev by Date: Re: Import specific columns from a tsv-file
  • Next by Date: Re: Changing names of variables in a loop
  • Previous by thread: Re: mathematica 6.0.3 and mac os x 10.5.5 crashes?
  • Next by thread: Re: ByteCount of imported machine-precision data matrix three times