extracting the result

38 views
Skip to first unread message

Ali Esmaeilpour

unread,
May 31, 2019, 2:00:31 PM5/31/19
to YALMIP
Hello again professor. I wanted to extract my result and plot them. my result is sth like:

K is a cell 1*5 with sdpvar 10*22 in each cell
K is 10*110
K = [Ubar K]
Ubar is 10*55
K is 10*55

each sdpvar has some info like current value and coefficient range. which of these info should be extracted?
and another subject is that I have to read them one by one and copy them to excel? Isn't there an efficient way to ectract them?

Johan Löfberg

unread,
May 31, 2019, 2:25:29 PM5/31/19
to YALMIP

Ali Esmaeilpour

unread,
May 31, 2019, 3:04:20 PM5/31/19
to YALMIP
eh... if I get the results (K as Kalman gain and ubar) after running the code and there was an affine feedback structure like u=K*(x-xbar)+ubar how could I construct and simulate the closed loop system structure?

my code was:

clc;
clear
;
close all
;
%% Time structure
dt
=0.01;          %sampling time
%% System structure
A
= [1.02  -0.1
     
0.1   0.98];
B
= [0.5 0
   
0.05 0.5];
G
= [0.3 0
     
0 0.3];
Qf = [50 0
     
0 50];
[A, B] = c2d(A,B,dt);
[nx,nu] = size(B);
%% MPC parameters
Q  
= eye(2);
R  
= eye(2)*50;
N
= 5;
%% Building block matrices
I
= eye(2,2);
q
= 2;
m
= 2;
Qbar = blkdiag(Q,Q,Q,Q,Qf,R,R,R,R);
Fq = blkdiag(sqrt(Q),sqrt(Q),sqrt(Q),sqrt(Q),sqrt(Q),sqrt(Qf),sqrt(R),sqrt(R),sqrt(R),sqrt(R),sqrt(R));
Gxx = zeros(2*N , size(A,1));
for i = 1:N
   
Gxx(q*i-q+1:q*i , :) = A^i;
end
Gxu = zeros(2*N , 2*N);
for i = 1:N
   
for j = 1:i
     
Gxu(q*i-q+1:q*i , m*j-m+1:m*j) = A^(i-j)*(B);
   
end    
end
Gxw = zeros(2*N , 2*N);
for i = 1:N
   
for j = 1:i
   
Gxw(q*i-q+1:q*i , m*j-m+1:m*j) = A^(i-j)*(I);    
   
end
end
%% Solve using YALMIP
K
= sdpvar(repmat(10,1,N),repmat(22,1,N));
alpha
= 0.975;
r
= 1.96;
Sigmaw = eye(10,10);
Sigma0 = eye(2,2);
xbar0
= ones(2,20);
Cs = [Gxx*xbar0;zeros(12,20)];
hx
= [-1/sqrt(5);-2/sqrt(5)];
hu
= [0;0];
Ahat = [Gxx*xbar0 eye(10,2);zeros(12,20) zeros(12,2)];
Bhat = [Gxu;eye(12,10)];
Abar = [eye(11,10);zeros(11,10)];
M
= Gxx*Sigma0*Gxx' + Gxw*Sigmaw*Gxw';
Mhat = [M zeros(10,12);zeros(12,10) ones(12,12)];
Euhat = ones(22,20);
Ek = [zeros(12,10);eye(10,10)];
g
= 3;
constraint
=[];
objective
=0;
h
= zeros((2*N + 1) * size(hx,1), 1);
b
= sdpvar(N,1);
for k = 1:N      
Ekn1 = zeros(N,1);
Ekn1(k) = 1;
Ekn2 = zeros(N+1,1);
Ekn2(k) = 1;
h
(:,k) = [kron(Ekn2,hx);kron(Ekn1,hu)];
%b = norm(chol(M)*((Abar+Bhat*K{k}*Ek)'*h(:,k)));
objective = objective + 0.5*trace(Fq'
*(Ahat+Bhat*K{k})*Mhat*(Ahat+Bhat*K{k})'*Fq);
constraint = [constraint, ((h(:,k)'
*(Cs+Bhat*K{k}*Euhat))+(r*b(k)))<=g, [b(k) (h(:,k)'*(Abar+Bhat*K{k}*Ek));((Abar+Bhat*K{k}*Ek)'*h(:,k)) b(k)*inv(Gxx*Sigma0*Gxx' + Gxw*Sigmaw*Gxw')]>=0];
end
options
= sdpsettings('solver','mosek');
optimize
(constraint,objective,options);
K
= value(K);


Ali Esmaeilpour

unread,
May 31, 2019, 3:07:14 PM5/31/19
to YALMIP

Johan Löfberg

unread,
May 31, 2019, 3:09:45 PM5/31/19
to YALMIP
Once you have the numerical values of from your solution, you are outside YALMIP and it is no longer a question of yalmip or optimization, but simply up to you to do what ever you want with those numbers

Ali Esmaeilpour

unread,
Jun 1, 2019, 8:52:41 AM6/1/19
to YALMIP
eh... excuse me professor how can I have info about the states? controller? input system that optimizer uses? output system after optimization?

Ali Esmaeilpour

unread,
Jun 1, 2019, 9:00:40 AM6/1/19
to YALMIP
nx and nu are size(B) which means two inputs two outputs I suppose...
but this system is lifted and there are block matrices Gxx etc
and after optimization my ubar is 10*55
and kalman gain 10*55
and there is an affine feedback u = K * (x - xbar) + ubar






























































Johan Löfberg

unread,
Jun 1, 2019, 9:29:09 AM6/1/19
to YALMIP
If you want to simulate the discrete-time system, you do that. You've computed and extracted the controller, it is up to you to use it for what ever you want, you are not in YALMIP any longer
Reply all
Reply to author
Forward
0 new messages