MATLAB: Symbolic simplification issue with exact division of polynomial by monomial

simplificationsymbolic

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?

Best Answer

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?
Related Question