Hello professor Lofberg
I've problem wit the following code. It says "Model creation failed" and see
https://yalmip.github.io/squareroots/ but after reading that article I couldn't figure out how to debug my code.
my code is:
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 = [-0.447213595499958;-0.894427190999916;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
for k = 1:N
b = sqrt(h'*((Abar+Bhat*K{k}*Ek)*M*(Abar+Bhat*K{k}*Ek)')*h);
objective = objective + 0.5*trace(Fq'*(Ahat+Bhat*K{k})*Mhat*(Ahat+Bhat*K{k})'*Fq);
constraint = [constraint, ((h'*(Cs+Bhat*K{k}*Euhat))+(r*b))<=g, [b^2 (h'*(Abar+Bhat*K{k}*Ek));((Abar+Bhat*K{k}*Ek)'*h) (Gxx*Sigma0*Gxx' + Gxw*Sigmaw*Gxw')]>=0];
end
options = sdpsettings('solver','sedumi');
optimize (constraint,objective,options);
K = value(K);