Symbolic simplification issue with exact division of polynomial by monomial

I am writing a code and at some point I have an exact division of a polynomial with a monomial; however, simplification does not seem to work
Ex:
((x1 + y2 - x1*y2)*(- x2^2*y1 + x2^2 + x2*y1^2 - y1^2)*(2*x1 + x2 + y1 - x1*x2 - x1*y1 - 1))/(x2 - y1) does not simplify.
However, notice that the middle factor in numerator (- x2^2*y1 + x2^2 + x2*y1^2 - y1^2) is divisible by (x2-y1) and MATLAB; indeed, simplifies (- x2^2*y1 + x2^2 + x2*y1^2 - y1^2)/(x2 -y1) and gives x2 + y1 - x2*y1.
How could I get around this issue?

 Risposta accettata

Sometimes, you have to lead it gently by the hand if you want it to do everything:
syms x1 x2 y1 y2
f = ((x1 + y2 - x1*y2)*(- x2^2*y1 + x2^2 + x2*y1^2 - y1^2)*(2*x1 + x2 + y1 - x1*x2 - x1*y1 - 1))/(x2 - y1);
f1 = expand(f);
f1 = simplify(collect(f1))
f1 =
(x1 + y2 - x1*y2)*(x2 + y1 - x2*y1)*(2*x1 + x2 + y1 - x1*x2 - x1*y1 - 1)
Is that the sort of result you want?

2 Commenti

Thanks for the great answer. I just tried first using factor and then dividing and finally simplifying and it worked fine. Thanks a lot!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by