how to obtain different solutions in yalmip

148 views
Skip to first unread message

Wail Hamdi

unread,
Jul 11, 2022, 5:05:03 PM7/11/22
to YALMIP
Hello, sir Johan,
when using YALMIP I always get the same solutions,
what to do to obtain different solutions
for example the following code:
yalmip('clear')
P = sdpvar(2);
A1=[-0.5 -5; -3 -1];
A2=[-0.5 -2; -7 -1];
F=[A1'*P+P*A1 <= 0;A2'*P+P*A2 <= 0;P >= 0];
options = sdpsettings('solver','mosek');
sol = optimize(F,[],options);
if sol.problem == 0
    P=value(P)
    display('Successfully solved');
else
    display('Hmm, something went wrong!');
    sol.info
    yalmiperror(sol.problem)
end

Johan Löfberg

unread,
Jul 11, 2022, 5:19:03 PM7/11/22
to YALMIP
This particular problem only has one solution, P=0, as this homogeneous problem is infeasible once dehomogonized.

Wail Hamdi

unread,
Jul 11, 2022, 7:07:42 PM7/11/22
to YALMIP
I don't mean precisely this example, I mean at any time when I use YALMIP  I always obtain the same solution, what do I have to do to get another solution if there are any solutions

Johan Löfberg

unread,
Jul 12, 2022, 3:37:03 AM7/12/22
to YALMIP
Sounds like you have some kind of misconception about solutions, as I cannot see any situation where magically all problems would lead to the same solution (beyond the trivial fact that solvers are deterministic so if you solve the same problem twice, you will get the same solution). You would have to illustrate with an example what you mean

Wail Hamdi

unread,
Jul 12, 2022, 9:10:33 AM7/12/22
to YALMIP
Ok, for example, in the following code, no matter how many times I run it I obtained always the same matrix P and K, but if you run it, you will obtain other solutions but you will obtain the same ones no matter how many times you run the code, I want to obtain different P and K than those that I obtained always because the feasibility area contains more than just one P and K.
clc;clear;
Am1=[0 0;
     0.0262 -0.2381];

Am2=[0 0;
     0.0262 -0.3142];

Am3=[0 0;
    -0.0262 -0.2381];

Am4=[0 0;
    -0.0262 -0.3142];
Am={Am1,Am2,Am3,Am4};

A0=[-0.5 5;
    0 -1];

C=[1 0;
   0 0];

yalmip('clear');
Tolerance=0.001;
Order_of_system_n=size(C,2);
Number_of_row_of_C_n=size(C,1);
Number_Of_Sub_Systems=size(Am,2);
P=sdpvar(Order_of_system_n,Order_of_system_n);
K=sdpvar(Order_of_system_n,Number_of_row_of_C_n);
F=[];
F=[F,P >= Tolerance,K>= Tolerance];
for i=1:Number_Of_Sub_Systems
F=[F , A0'*P + P*A0 + Am{i}'*P + P*Am{i} - C'*(K)' - K*C  <= -Tolerance ];
end


options = sdpsettings('solver','mosek');

sol = optimize(F,[],options)
if sol.problem == 0
    P=value(P)
    eig(P)
    K=value(K);
    L=inv(P)*K

    display('Successfully solved');
else
    display('Hmm, something went wrong!');
    sol.info
    yalmiperror(sol.problem)
end

Johan Löfberg

unread,
Jul 12, 2022, 10:09:40 AM7/12/22
to YALMIP
Why would you expect any solver of returning different solutions when you keep solving exactly the same feasibility problem? You can run it for years, and a deterministic solver will return the same thing.

To get different solutions, you have to change something, such as an objective

BTW, to get positive definite solutions, you want  >= eye(n)*tolerance, not >=tolerance. The similar thing you have on K I have no idea what you intend to do as positivity of the transformed state-feedback is a weird constraint

Wail Hamdi

unread,
Jul 12, 2022, 10:30:01 AM7/12/22
to YALMIP
I just expected from the solver to return a different solution because the same code in two different PC is different, so I thought that there is a way to obtain a different solution;
yes changing something is the way that I always use to do such a thing for example -100<=K(:)<=100, but I thought that there is a formal way to do that in yalmip
K is just an example, not state feedback.
thank you sir Johan

Johan Löfberg

unread,
Jul 12, 2022, 10:39:11 AM7/12/22
to YALMIP
The standard approach is to use random objectives in different directions
Reply all
Reply to author
Forward
0 new messages