The problem can be summarized as: Given , estimate , where , where is the error introduced by the quantization.
The task is given by
% Standard form (Hint: Standard form requires all variables to be positive. Use a similar trick as above.)
c =
D =
d =
LB =
UB =
% zopt = linprog(c,[],[],D,d,LB,UB); % If we want, we can verify that we get the same solution
% xopt = zopt(1:nx) - zopt(nx+1:2*nx);
% Dual problem
[lambdaopt,fval,exitflag,output,Zopt] = linprog(,,); % Specify the three first input parameters!
And the solution is given by
% Standard form (Hint: Standard form requires all variables to be positive. Use a similar trick as above.)
c = [zeros(1, 2*nx) ones(1, L) ones(1, L)]; % Adjust c to include x+ and x-
% Adjust D to include x+ and x- parts
D = [A -A eye(L) -eye(L)];
d = y; % stays the same
% New bounds, all non-negative
LB = zeros(1, 2*nx + 2*L); % Lower bounds
UB = []; % Upper bounds not necessary, implies infinity
% zopt = linprog(c,[],[],D,d,LB,UB); % If we want, we can verify that we get the same solution
% xopt = zopt(1:nx) - zopt(nx+1:2*nx);
% Dual problem
[lambdaopt,fval,exitflag,output,Zopt] = linprog(-d,D',c'); % Specify the three first input parameters!
xopt = Zopt.ineqlin(1:nx) - Zopt.ineqlin(nx+1:2*nx); % The optimal z is now the lagrangian multiplier of the inequality constraint
figure(2)
stairs(0:10,[x;x(end)]); xlabel('t'); ylabel('u(t)'); hold on;
stairs(0:10,[xopt;xopt(end)],'r--'); hold off;