Is there a mature tool for solving KKT equations in Matlab?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Thanks for reading!
I tried to solve KKT equations by the function "solve" and find it doesn't work when there are multiple solutins. The code is based on https://github.com/sokratisathancsd/kktConditions-Matlab-csdauth
The KKT code is good, so I won't show it. But I find that the solve function which is used there can't show all the multi-solutions, which seems to be the problem of the function solve:
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1409594/image.png)
My main question is: what's the better way to calculate KKT equations? Do you have better tools?
0 commentaires
Réponses (1)
Robert Reed
le 14 Juil 2023
Have you tried the MATLAB backslash operator? It does very well for me, even for ill-conditioned problems. I think it uses Cholesky decomposition. There is also a generalized QR decomposition on the File Exchange that is slightly less robust but nevertheless quite good. Robert. A. Reed
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!