Clear Filters
Clear Filters

Is there a mature tool for solving KKT equations in Matlab?

10 views (last 30 days)
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)
x1_sol = 
x2_sol = 
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.
If you have any idea why this happens, please refer to this question.
My main question is: what's the better way to calculate KKT equations? Do you have better tools?

Answers (1)

Robert Reed
Robert Reed on 14 Jul 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

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!