# Help with solve under the symbolic environment

3 views (last 30 days)
Bruno Souza on 6 Aug 2020
Answered: Walter Roberson on 6 Aug 2020
Hi all,
I'm trying to solve a system of 2 non linear equations using the symbolic envinronment. However, when I check if the solution match the equation i generated, the result is not the same! Here is what I get:
clear
%Calibration
p0 = 0.05;
p1 = 0.1;
lambda = 0.1;
ybar = 1;
kappa = 0.9;
b0 = 0.5;
c1 = 0.4;
alpha = (ybar*lambda*(1-p0)/p1);
beta = ((p1 - kappa*p0)/p1);
%Solving symbolically
syms w ML
[solw,solML] = solve(w == (0.5*ybar*(1- p0 - ML*(p1+lambda*(p0-1)) - (ML^2)*lambda*p1))/(1 - p0 - ML*(p1-kappa*p0) + (ML^2)*kappa*p1), ...
ML == 0.5*(1/(lambda*ybar+kappa*w))*(((ybar*lambda*(1-p0))/p1) + ((p1 - kappa*p0)/p1)*w - ybar));
w_star = double(solw);
ML_star = double(solML);
%Take the real root
w_sol = w_star(3)
ML_sol = ML_star(3)
%Check to see if the solution is OK
ML_check = 0.5*(1/(lambda*ybar+kappa*w_sol))*(((ybar*lambda*(1-p0))/p1) + ((p1 - kappa*p0)/p1)*w_sol - ybar)
if ML_sol == ML_check
disp("The solution match!")
else
disp("We have a problem: the value from the solution is not the same generated by the equation")
end
w_sol =
0.2051
ML_sol =
0.5032
ML_check =
0.1103
We have a problem: the value from the solution is not the same generated by the equation
Am I missing something really stupid? I'm using the same procedure for other versions of the model, and in all other cases the solution matches the generated by the equations.
Thank you,
Bruno

Walter Roberson on 6 Aug 2020
%Calibration
p0 = 0.05;
p1 = 0.1;
lambda = 0.1;
ybar = 1;
kappa = 0.9;
b0 = 0.5;
c1 = 0.4;
alpha = (ybar*lambda*(1-p0)/p1);
beta = ((p1 - kappa*p0)/p1);
%Solving symbolically
syms w ML
[solw,solML] = solve(w == (0.5*ybar*(1- p0 - ML*(p1+lambda*(p0-1)) - (ML^2)*lambda*p1))/(1 - p0 - ML*(p1-kappa*p0) + (ML^2)*kappa*p1), ...
ML == 0.5*(1/(lambda*ybar+kappa*w))*(((ybar*lambda*(1-p0))/p1) + ((p1 - kappa*p0)/p1)*w - ybar), [w, ML]);
w_star = double(solw);
ML_star = double(solML);
%Take the real root
%Check to see if the solution is OK
ML_check = 0.5*(1/(lambda*ybar+kappa*w_sol))*(((ybar*lambda*(1-p0))/p1) + ((p1 - kappa*p0)/p1)*w_sol - ybar)
if ML_sol == ML_check
disp("The solution match!")
elseif ismembertol(ML_sol, ML_check)
disp("The solutions do NOT match! The solutions only match to within round-off tolerance!")
else
disp("We have a problem: the value from the solution is not the same generated by the equation")
end
You did not specify the order of output variables, and the order you assumed was the opposite of what MATLAB guessed you wanted.
You should never expect that two floating point values calculated different ways will be bit-for-bit identical. In this case, the two differ by 2*eps(ML_sol)