Re: Help

82 views
Skip to first unread message
Message has been deleted

Johan Löfberg

unread,
May 8, 2026, 4:17:10 AM (13 days ago) May 8
to YALMIP
Where are you stuck? It looks pretty straightforward

P = sdpvar(n);
for i = 1:r
Sii = ...
Model = [Model, Sii <= 0]
for j = 1:r
 Sij = ...
Model = Model, 2/(r-1)*Sij...
end
end


On Thursday, 7 May 2026 at 22:14:37 UTC+2 ineh...@gmail.com wrote:
Hello, I am having difficulty understanding how to formulate and implement these LMIs correctly in YALMIP. Could you please help me with how to write this formulation properly? I would really appreciate your guidance.Screenshot_20260507-205845_ChatGPT.png

Johan Löfberg

unread,
May 8, 2026, 4:53:55 AM (13 days ago) May 8
to YALMIP
...and there are some unclear issues in your description

GPT 5.5 tells the story very well.

https://chatgpt.com/share/69fda406-5448-83eb-b45c-83e5f0901061
Message has been deleted
Message has been deleted

Johan Löfberg

unread,
May 8, 2026, 7:31:14 AM (13 days ago) May 8
to YALMIP
I got errors is a pretty vague description.

However, as ChatGPT says in the link your model does not make sense as S{i,i} is not symmetric, thus S{i,i} < 0 is not something a semidefinite solver can help you with (YALMIP probably warns you that you are using a non-symmetric square matrix in a constraint and thus either have made a mistake, or misunderstood the theory)

On Friday, 8 May 2026 at 12:30:33 UTC+2 ineh...@gmail.com wrote:
 I used ChatGPT and got errors. Is it correct?
S = cell(r,r);
Tol = 1e-10;
Constraints = [];

Constraints = [Constraints, P >= Tol*eye(n)];


for i = 1:r
    for j = 1:r

        S{i,j} = [A{i}'*P + P*A{i}    E{j};
                   M*C{j}             zeros(p,q)];

    end
end


for i = 1:r
    for j = 1:r

        if i == j

            Constraints = [Constraints, ...
                S{i,i} <= -Tol*eye(size(S{i,i},1))];

        else

            Constraints = [Constraints, ...
                (2/(r-1))*S{i,i} + S{i,j} + X{j,i} ...
                <= -Tol*eye(size(S{i,i},1))];

        end

    end
end
Message has been deleted

Johan Löfberg

unread,
May 8, 2026, 8:14:30 AM (13 days ago) May 8
to YALMIP
Well, it is sensible MATLAB code, but the model makes no sense as S{i,i} trivially cannot be negative definite

On Friday, 8 May 2026 at 14:08:04 UTC+2 ineh...@gmail.com wrote:

Sorry, I didn’t explain my idea clearly, this is just an example. Are the constraints written correctly?

S = cell(r,r);

Tol = 1e-10;
Constraints = [];

Constraints = [Constraints, P >= Tol*eye(n)];


for i = 1:r
    for j = 1:r

        S{i,j} = [A{i}'*P + P*A{i}    E{j};
                   E{j}'             zeros(p,q)];
Message has been deleted

Johan Löfberg

unread,
May 8, 2026, 8:24:06 AM (13 days ago) May 8
to YALMIP
Yes, YALMIP is standard MATLAB code, and your code looks very standard.

On Friday, 8 May 2026 at 14:20:49 UTC+2 ineh...@gmail.com wrote:

The matrix is written incorrectly because this is just an example and I didn’t pay attention. What I want to verify, regardless of the matrix itself, is whether the constraints are written correctly ??

Message has been deleted

Johan Löfberg

unread,
May 8, 2026, 9:02:41 AM (13 days ago) May 8
to YALMIP
Impossible to answer as we have no idea what you mean with "incorrect"

If it runs without any diagnostic error codes, well then the code is correct. Whether the model or data is correct is impossible for anyone else to know.

On Friday, 8 May 2026 at 14:57:29 UTC+2 ineh...@gmail.com wrote:
I have already defined the matrices C0, E0  and A_{TS}. This is a part of my code. Are there any issues in it? I am still obtaining incorrect results, and these are the eigenvalues of the matrix P  
    0.0000
    0.0002
    0.9644  
yalmip('clear');
n = size(C0,2);  
p = size(C0,1);  
r = length(A_TS);

P = sdpvar(n,n,'symmetric');
gamma = sdpvar(1);

% Li bar (Lbar)
Lbar = cell(r,1);
for i=1:r
    Lbar{i} = sdpvar(n,p,'full');
end
%C
C = cell(1,r);


for j = 1:r
    C{j} = C0;
end

%E
E = cell(1,r);


for i = 1:r
    E{i} = E0;
end

% M
M = sdpvar(p,p,'full');
q = size(E0,2);

X = cell(r,r);


Tol = 1e-10;

Constraints = [];

Constraints = [Constraints, P >= Tol*eye(n)];
Constraints = [Constraints, gamma >= Tol];


for i = 1:r
    for j = 1:r

        X{i,j} = [ ...

        A_TS{i}'*P + P*A_TS{i} ...
        - Lbar{i}*C{j} - C{j}'*Lbar{i}', ...
        P*E{i}, ...
        -Lbar{i}, ...
        C{j}'*M';

        E{i}'*P, ...
        -gamma*eye(q), ...
        zeros(q,p), ...
        zeros(q,p);

        -Lbar{i}', ...
        zeros(p,q), ...
        -gamma*eye(p), ...
        M' - eye(p);

        M*C{j}, ...
        zeros(p,q), ...
        M - eye(p), ...
        -gamma*eye(p)


        ];

    end
end

for i = 1:r
  for j = 1:r
      if i == j
    Constraints = [Constraints, ...
        X{i,i} <= -Tol*eye(size(X{i,i},1))];

      else
            Constraints = [Constraints, ...
                (2/(r-1))*X{i,i} + X{i,j} + X{j,i} ...
                <= -Tol*eye(size(X{i,i},1))];

      end

    end
end

Objective = gamma;
options = sdpsettings('solver','mosek');
sol = optimize(Constraints, Objective, options);
if sol.problem == 0
    disp('Feasible');
else
    disp('Infeasible or numerical issue');
end

     P= value(P)
     gamma= value(gamma)
L = cell(r,1);
for i=1:r
    L{i} = value(P) \ value(Lbar{i});

end

M= value(M)
 L1 = L{1}
 L2 = L{2}

Han Ine

unread,
May 8, 2026, 9:16:09 AM (13 days ago) May 8
to YALMIP
Yes, it works, but the matrices may be written incorrectly, or the tolerance may be wrong, or the constraints may be formulated incorrectly. Could you check it, please?

Johan Löfberg

unread,
May 8, 2026, 9:20:17 AM (13 days ago) May 8
to YALMIP
How could anyone else know if your matrices are written incorrectly or tolerances are wrong. As I said, it is reasonable YALMIP/MATLAB code, but whether it is correct is impossible for anyone else to know.

Han Ine

unread,
May 8, 2026, 9:27:34 AM (13 days ago) May 8
to YALMIP
Thank you for being so helpful
Reply all
Reply to author
Forward
0 new messages