4
$\begingroup$
Subscript[x, 1] = (a x + b)/(c x + d);
CoefficientList[
 Simplify[(α + β Subscript[x, 1] + γ Subscript[x, 
       1]^2) (D[Subscript[x, 1], x]^-1)] /. a d - b c -> 1, x]

gives

General::poly: "(d+c\x)^2\ (α+((b+a\x)(d\β+c\x\β+(b+a\x)\γ))/(d+c\x)^2) is not a polynomial."

This is strange, because

Simplify[(α + β Subscript[x, 1] + γ Subscript[x, 
      1]^2) (D[Subscript[x, 1], x]^-1)] /. a d - b c -> 1

always give

(c x+d)^2 (((a x+b) (γ (a x+b)+β c x+β d))/(c x+d)^2+α)

which should be the more simpler version

(a x+b) (γ (a x+b)+β c x+β d)+α (c x+d)^2

which is a polynomial.

BTW, how to get this question better formatted?

$\endgroup$
  • $\begingroup$ You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$ – Michael E2 Sep 16 '15 at 12:43
9
$\begingroup$

What you have there is in the form of a rational function:

Simplify[(α + β Subscript[x, 1] + γ Subscript[x, 1]^2) (D[Subscript[x, 1], x]^-1)]

Mathematica graphics

If you Expand and then Simplify, you get a polynomial.

Subscript[x, 1] = (a x + b)/(c x + d);
CoefficientList[
 Simplify@Expand[(α + β Subscript[x, 1] +
   γ Subscript[x, 1]^2) (D[Subscript[x, 1], x]^-1)] /. a d - b c -> 1, x]
(*
  {d^2 α + b d β + b^2 γ, 
   2 c d α + b c β + a d β + 2 a b γ, 
   c^2 α + a c β + a^2 γ}
*)

Checking the pieces of your computation, as in the first step above, is a good way to debug one's code.

$\endgroup$
  • 2
    $\begingroup$ This appears to be a weakness in CoefficientList since its documentation states "CoefficientList works whether or not poly is explicitly given in expanded form." $\endgroup$ – Bob Hanlon Sep 16 '15 at 13:07
  • $\begingroup$ @BobHanlon: I think "expanded" there means "multiplied out", which is what Expand does; Simplify is what cancels the factors in the denominator. Internally, CoefficientList probably tests for a polynomial by looking for an expression made out of Plus and Power objects the latter of which need to have positive second arguments. (Actually, it probably just calls PolynomialQ, but I would imagine that the above is what that latter function does internally.) $\endgroup$ – Michael Seifert Sep 16 '15 at 14:16
  • $\begingroup$ That was great! Expand works very well. $\endgroup$ – eccstartup Sep 18 '15 at 10:47

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.