0
$\begingroup$

The polynomial is as follows:

xpoly=-a^2 b^2 + (b^2 + a^2 k^2) x^2 + a^2 k^2 x0^2 - 2 a^2 k x0 y0 + 
 a^2 y0^2 + x (-2 a^2 k^2 x0 + 2 a^2 k y0)

How to get the results I want:

(b^2 + a^2 k^2) x^2+x (-2 a^2 k^2 x0 + 2 a^2 k y0)+a^2 k^2 x0^2 - 2 a^2 k x0 y0 + a^2 y0^2-a^2 b^2

If I want to get a further result, it is to factorize each item and how to deal with it. The further result is as follows:

(b^2 + a^2 k^2) x^2+2a^2 k (- k x0 + y0)x+a^2 k^2 x0^2 - 2 a^2 k x0 y0 + a^2 y0^2-a^2 b^2
    

(b^2 + a^2 k^2) x^2+2a^2 k (- k x0 + y0)x+a^2 k^2 x0^2 - 2 a^2 k x0 y0 + a^2 y0^2-a^2 b^2

The result in bold is what I finally want, and it is to combine the similar items and arrange them according to the descending power of x, and the coefficients in each similar item can be factorized. Or in the form of a whole

Thank you!

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica S.E. To start: 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, since the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) consider accepting the answer, if any, that solves your problem, by clicking checkmark sign, 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bmf
    Jan 23, 2023 at 4:51

1 Answer 1

2
$\begingroup$

One way of doing it is the following:

Collect[xpoly, x, # &, Defer[+##]~Reverse~2 &]

poly

Edit: we have established that

res = (b^2 + a^2 k^2) x^2 + 
   x (-2 a^2 k^2 x0 + 2 a^2 k y0) + (-a^2 b^2 + a^2 k^2 x0^2 - 
     2 a^2 k x0 y0 + a^2 y0^2);

Then, we can

Factor@FactorTerms[Coefficient[res, x], x]

res

However, after the edit in the OP it seems that the desired thing is to manipulate each term separately. I suggest

CoefficientList[xpoly, x] // Factor // FullSimplify

coeflist

Edit 2: it is obvious that the following

Collect[Coefficient[res, 
    x^2] x^2 + (Factor@FactorTerms[Coefficient[res, x], x]) x + 
  Select[res, FreeQ[x]], x, # &, Defer[+##]~Reverse~2 &]

gives

final

Edit 3: using only the code from the O.P -which means xpoly- and a one-liner

Collect[Coefficient[xpoly, x^2] x^2 +
  Factor@FactorTerms[Coefficient[xpoly, x], x] x + 
  Select[xpoly, FreeQ[x]], x, # &, Defer[+##]~Reverse~2 &]

2

$\endgroup$
24
  • $\begingroup$ excellent! thank you! If I want to get a further result, it is to factorize each item and how to deal with it. The further result is as follows: (b^2 + a^2 k^2) x^2+2a^2k (- k x0 + y0)x+a^2 k^2 x0^2 - 2 a^2 k x0 y0 + a^2 y0^2-a^2 b^2 $\endgroup$
    – csn899
    Jan 23, 2023 at 4:50
  • $\begingroup$ @csn899 please see the edit. $\endgroup$
    – bmf
    Jan 23, 2023 at 5:01
  • $\begingroup$ thank you! I want the complete equation form, not the coefficient of a single term. That is to say, the equations are arranged according to the descending power of x after merging the similar terms. What is better is that the coefficients in front of each term of the equation can be factorized. Overall maintenance of equation $\endgroup$
    – csn899
    Jan 23, 2023 at 5:37
  • $\begingroup$ Factor@FactorTerms[Coefficient[res, x], x] the result is:-2 a^2 k (k x0 - y0) $\endgroup$
    – csn899
    Jan 23, 2023 at 5:40
  • $\begingroup$ CoefficientList[xpoly, x] // Factor // FullSimplify the result is:{-a^2 (b + k x0 - y0) (b - k x0 + y0), 2 a^2 k (-k x0 + y0), b^2 + a^2 k^2} $\endgroup$
    – csn899
    Jan 23, 2023 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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