MATLAB: Logical False before subs then Logical True

logical?MATLABsubssymbolicSymbolic Math Toolbox

I am trying to verify if 2 equations are symbolically equivalent. I did a logical check and it return false. When I solve these equations in terms of S/K by using a variable substitution, i.e. Z=S/K -> K=S*K, the logical is true. I can't seem to figure out why this is so.
syms S K r_x Z D
Solution=solve(0 == -S*(r_x)^2 + 2*(K+S)*r_x -S,r_x )
Expanded_Solution=expand(Solution(2,1))
%Sections=children(Expanded_Solution)
D=1 + (K/S) - sqrt( (1+(K/S))^2 -1)
Boolen_check_1=logical(D == Expanded_Solution)
% Z=K/S --> K = Z*S
new_1=subs(Expanded_Solution,K, (Z*S) )
new_2=subs(D,K, (Z*S))
trial_1=solve(new_1 - r_x == 0, Z)
trial_2=solve(new_2 - r_x == 0, Z)
Boolen_check_2 = logical(trial_1 == trial_2)

Best Answer

You can’t prove two symbolic equations which are in different form that are equal (matlab won’t recognise), the last thing which you did by substituting is the appropriate way
simple try :
fplot(subs(Expanded_Solution,K,2 ))
hold on
fplot(subs(D,K,2))
and see the difference between the graph when you change the form of an equation the behaviour is totally different
Always use isequaln()(link) to compare symbolic equations.
Related Question