Q:

MATLAB subs(): Strange behaviour

syms Gr Ra Ri A B Gr1 Gr2 c d
Gr =  2*c*(Ra^2 - Ri^2) - d*(Ra^4 - Ri^4)/2;
Gr1 = subs(Gr, [c*(Ra^2 - Ri^2), -d*(Ra^4 - Ri^4)/2], [A, B])
Gr2 = subs(Gr, [c*(Ra^2 - Ri^2),  d*(Ra^4 - Ri^4)/2], [A, B])

returns 
Gr1 =

2*A + B

Gr2 =

2*A - (d*(Ra^4 - Ri^4))/2

Is there a way to convince MATLAB to return Gr2 = 2*A - B in the second case without workarounds? I have a much more complex expression to substitute, but I can't work with this subs()-behaviour. Thanks.

A:

The described behaviour was classified by the Matlab development team as unexpected and will hopefully be fixed in future releases:
http://www.mathworks.com/matlabcentral/answers/213727-subs-unexpected-simplification-behaviour#answer_177179

