% This code solve a simple SDP problem:
%
%  minimize  trace(X)
%  subject to:
%  X = X' >= 0
%  |trace(E1*X) - d1|<=eps
%  |trace(E2*X) - d2|<-eps
%

E1 = [1 2 0;
    2 -1 3;
    0 3 1];
E2 = [1 0 -1;
    0 0 0;
    -1 0 1];

d1 = 4;
d2 = 8;
n = 3;
epsvect = [0.1,0.05,0.02,0.01,0.001,0.0001];
for jj=1:length(epsvect)

epsx=epsvect(jj);
fprintf(1,sprintf('Computing the optimal solution for eps=%f ... ',epsx));

cvx_begin sdp
cvx_quiet true

    variable X(n,n) semidefinite;
    dual variable y1;
    dual variable y2;
    minimize trace(X);
    subject to
    y1: abs(trace(E1*X)-d1)<=epsx;
    y2: abs(trace(E2*X)-d2)<=epsx;
    
cvx_end


fprintf(1,'Done with status cvx_status = %s    \n',cvx_status);
        
if (cvx_status == 'Solved')
    % Display results
    disp('The computed optimal solution is:')
    disp(X);

    disp('Dual variables:')
    disp(y1) , disp(y2)
end

end % end for eps
