How does the function "solve" deal with infinite solutions? Why can't it show all the solutions?
Show older comments
Thanks for reading!
I read some similar quetions. But none of the answers give the reason behind the chosen terms.
clear;
clc;
syms x y;
eq = sin(x)-sin(y);
st = [x -x+2*pi y -y+2*pi];
sol = solve([eq,st>=0],'Real',true);
sol.x
sol.y
It makes me very curious about why solve function choose these two terms from all the infinite solutions. Is it a random action? At first, I assume the result might be (0,0) and (2pi,2pi) since it would be more reasonable if the ends are chosen(at least it's not random).
In fact, there would also be problem even there is only finite solusions:
clear;
%%
syms f(x1,x2)
f(x1,x2)=sin(x1).^2+sin(x2).^2;
fx1(x1,x2)=diff(f,x1);
fx2(x1,x2)=diff(f,x2);
g1(x1,x2) = x1;
g2(x1,x2) = -x1+pi*2;
g3(x1,x2) = x2;
g4(x1,x2) = -x2+pi*2;
g=[g1,g2,g3,g4];
%klisi KKT
[x1_sol,x2_sol]=solve([fx1,fx2,g>=0],[x1,x2],'Real',true)
Clearly, (pi,pi) should also be one of the solutions, so the solution is not enough. In fact, there should be 25 solutions as I can see in the following figure.

In fact, this question comes from KKT conditions. I tried to solve KKT equations by the function "solve" and find it doesn't work when there are infinite solutins. And it can't show the finite answers completely, neither.
If you have tools for solving KKT equation better, please refet tothis question.
Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

