Clear Filters
Clear Filters

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

29 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
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:
syms f(x1,x2)
g1(x1,x2) = x1;
g2(x1,x2) = -x1+pi*2;
g3(x1,x2) = x2;
g4(x1,x2) = -x2+pi*2;
%klisi KKT
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





Community Treasure Hunt

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

Start Hunting!