How to preallocate an 'lmi' (Yalmip class) array of known size
35 ビュー (過去 30 日間)
古いコメントを表示
Hello. I use YALMIP to solve linear matrix inequalities. Currenly, I create the constraint vector, F, that gets passed to the 'optimize' function like this:
P = sdpvar(n,n,'symmetric');
F = [P >= eye(n),...
A_comb(:,:,1)'*P*A_comb(:,:,1)-P <= 0,...
A_comb(:,:,2)'*P*A_comb(:,:,2)-P <= 0,...
A_comb(:,:,3)'*P*A_comb(:,:,3)-P <= 0,...
A_comb(:,:,4)'*P*A_comb(:,:,4)-P <= 0]
options = sdpsettings('solver', 'sedumi');
sol = optimize(F,0,options); % Objective function=0, only checking feasibility
P_opt = value(P);
Where A_comb(:,:,i) are vertices of the n-by-n array space invloved in the linear matrix inequalities and P is a positive definite matrix satisfying the discrete Lyapunov equation. I am interested in making this code more general for any dimension LMI. In this case, the dimension is 4. But if i had another problem with the same structure of constraints (just more of them), I would like to have a loop that constructs F. I noticed that F has the class of 'constraint' if it has only one constraint, and a class of 'lmi' if it has more than one constraint. Not sure why that is. Is there a way initialize F with the class of 'lmi'? I tried this so far:
P = sdpvar(n,n,'symmetric');
F = repmat([P >= eye(n)],n+1,1)
for i = 1:n
F(i+1) = A_comb(:,:,i)'*P*A_comb(:,:,i)-P <= 0
end
options = sdpsettings('solver', 'sedumi');
sol = optimize(F,0,options); % Objective function=0, only checking feasibility
P_opt = value(P);
The problem with this is if I try to call out an index of F other than 1, I get the error
Error using indexing
LMI #2 not available.
I looked throught the YALMIP-master directory I downloaded, but I could not find the code that created the 'lmi' class. Any help is appreciated.
Edit:
I also found that this works:
P = sdpvar(n,n,'symmetric');
F = [P >= eye(n)];
for i=1:4
F = [F, A_comb(:,:,i)'*P*A_comb(:,:,i)-P <= 0];
end
options = sdpsettings('solver', 'sedumi');
sol = optimize(F,0,options); % Objective function=0, only checking feasibility
P_opt = value(P);
But the problem is that the size of F is changing with every iteration. When the dimension of the LMI if large, this will make the code run slower.
0 件のコメント
回答 (1 件)
Snehal
約5時間 前
編集済み: Snehal
32分 前
Hello,
I understand that you are trying to solve linear matrix inequalities using YALMIP such that it executes efficiently for variable number of constraints.
You can consider using a cell array to store constraints in YALMIP for improved performance since this avoids the computational overhead of resizing the matrix during each iteration. This cell array of constraints can then be combined into a single constraint object and stored in ‘F’.
Here’s a sample code snippet for your reference:
n = size(A_comb, 1);
num_constraints = size(A_comb, 3);
P = sdpvar(n, n, 'symmetric');
constraints = cell(num_constraints + 1, 1);
constraints{1} = P >= eye(n);
for i = 1:num_constraints
constraints{i+1} = A_comb(:,:,i)' * P * A_comb(:,:,i) - P <= 0;
end
F = [constraints{:}];
options = sdpsettings('solver', 'sedumi');
sol = optimize(F, 0, options); % Objective function=0, only checking feasibility
P_opt = value(P);
This approach avoids resizing ‘F’ repeatedly and should be more efficient.
Regarding the class type of variable ‘F’, YALMIP internally manages the representation of such constraints. A single constraint is represented by the ‘constraint’ class, while multiple constraints are managed by the ‘lmi’ class to efficiently handle lists of linear matrix inequalities. Therefore, you do not need to manually initialize ‘F’ as an ‘lmi’, YALMIP will manage the class transition internally.
Also, when trying to execute one of the mentioned code implementations, the error "Error using indexing: LMI #2 not available" occurs because the code attempts to index into a YALMIP constraint object ‘F’ (inside the ‘for’ loop) as if it were a standard MATLAB array, which is not supported by YALMIP's internal constraint management system.
Hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で LMI Solvers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!