0

I used the following snippet to simplify an equation:

syms P Q R S T U V A B C D E F G X Y
simplify((X - A)^2 + (Y - B)^2 - (X - B)^2 - (Y + A)^2)

Which gives me the result:

2*B*X - 2*A*Y - 2*A*X - 2*B*Y

On the other hand,

simplify((X - A)^2 + (Y - B)^2 - (X - B)^2 - (Y + 2*A)^2)

gives the same result after just re-ordering:

(A - X)^2 - (B - X)^2 - (2*A + Y)^2 + (B - Y)^2

What changed between these two equations? Am I not using the function correctly?

Any help would be appreciated.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
iKnowNothing
  • 175
  • 11

2 Answers2

3

As per the documentation, you can increase the amount of simplification "steps" using:

simplify(expr,'Steps',nSteps); % e.g. nSteps = 50

You can also try other functions (combine, expand, factor, ...) for rearranging an expression.

I have the Maple symbolic toolbox for MATLAB and I get different results than you:

>> syms P Q R S T U V A B C D E F G X Y
>> simplify((X - A)^2 + (Y - B)^2 - (X - B)^2 - (Y + A)^2)

ans =

                         (-2 X - 2 Y) A + 2 B (X - Y)

>> simplify((X - A)^2 + (Y - B)^2 - (X - B)^2 - (Y + 2*A)^2)

ans =     
                         2
                     -3 A  + (-2 X - 4 Y) A + 2 B (X - Y)

In conclusion - it works as expected, you should give other functions/tools a try.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
  • Thanks @Dev-iL. :) I am an absolute beginner when it comes to using MATLAB. How can I install Maple Symbolic Toolbox? I have MATLAB 2015 Installed. – iKnowNothing Jul 05 '18 at 15:55
  • 1
    Well, when you install [Maple](https://www.maplesoft.com/index.aspx), it looks for a MATLAB installation on the local system and suggests you to install Maple integration. You can also install the toolbox later as explained [here](https://www.maplesoft.com/support/downloads/mtm1102_installation.aspx). You'll have to look into Maple-MATLAB version compatibility though (I just use the latest of both). – Dev-iL Jul 05 '18 at 15:57
2
(X - A)^2 + (Y - B)^2 - (X - B)^2 - (Y + A)^2
X^2 + A^2 - 2*A*X + Y^2 + B^2 - 2*Y*B - X^2 - B^2 + 2*X*B -Y^2 - A^2 + 2*Y*A
2*B*X - 2*A*Y - 2*A*X - 2*B*Y

Initial: 12 operations used to compute a number

Final: 12 operations used to compute a number


On the other hand:

(X - A)^2 + (Y - B)^2 - (X - B)^2 - (Y + 2*A)^2
X^2 + A^2 - 2*A*X + Y^2 + B^2 - 2*Y*B - X^2 - B^2 + 2*X*B -Y^2 - 4*A^2 + 4*Y*A
-3*A^2 + 2*B*X - 4*A*Y - 2*A*X - 2*B*Y

Initial: 13 operations used to compute a number

Final: 15 operations used to compute a number

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120