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.

  • 4
    $\begingroup$ FactorByVariable[p_, c_] := c Expand[p/c] where p is your polynomial, c is the variable you want to factor out. $\endgroup$ – IPoiler Oct 2 '15 at 3:21
  • $\begingroup$ haha... oh yeah. Thanks ! $\endgroup$ – anon01 Oct 2 '15 at 3:25
  • 3
    $\begingroup$ @IPoiler. You should write-up your comment as an answer. $\endgroup$ – m_goldberg Oct 2 '15 at 4:10

Defining a function like

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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