9

Very simple question, but I can't find a simple answer here or in the documentation. I have an expression:

qq = a x + b x^2 + c x^3

and wish to factor out a defined variable/constant to get for example:

qq = b (a/b x + x^2 + c/b x^3)

Bonus points for simplicity/readability.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
anon01
  • 231
  • 2
  • 7

1 Answers1

14

Defining a function like

Clear[FactorByVariable]
FactorByVariable[p_,c_]:=c Expand[p/c]

will be one of the simpler options. The argument p is the polynomial you wish to factor from and c is the variable you wish to factor out.

I think the reason you can't get your desired result with something like FactorTerms[a x + b x^2 + c x^3,{a,c,x}] is because Mathematica doesn't know if b divides a and c; though, specifying {a/b,c/b} \[Element] Integers didn't seem to make Simplify want to factor the b out either.

IPoiler
  • 1,230
  • 9
  • 15