Method on @sym: e = collect (f, x)

Collect common powers of a term in an expression.

An example of collecting terms in a polynomial:

syms x y
f = y*x^2 + x*y + x*y^2
  ⇒ f = (sym)
       2        2
      x ⋅y + x⋅y  + x⋅y

collect(f, x)
  ⇒ (sym)
       2       ⎛ 2    ⎞
      x ⋅y + x⋅⎝y  + y⎠

collect(f, y)
  ⇒ (sym)
         2     ⎛ 2    ⎞
      x⋅y  + y⋅⎝x  + x⎠

See also: @sym/expand.

Package: symbolic