function [answer, X, time] = cond_se_diag_dual(M,d,eta)

C = chol(M);

% s t x y

clear K At b c

n = size(d,1);
ub = d + eta;
lb = d - eta;

At = sparse(1,2 + 2*n);
c = sparse(1,1);

% box constraints
At(1:n,1:2+n) = [sparse(n,1) -ub speye(n)];
At(n+1:2*n,1:2+n) = [sparse(n,1) lb -speye(n)];
At(4*n+1,2) = -1;
At(2*n+1:3*n,3:2+n) = -speye(n);
At(3*n+1:4*n,3+n:2+2*n) = -speye(n);
c(1:4*n+1,1) = sparse(4*n+1,1);

K.l = 4*n + 1;

count = 4*n + 1;
% socp constraints
for i = 1:n
  At(count + 3*(i-1)+1,[2+i 2+n+i]) = [-0.5 -0.5];
  At(count + 3*(i-1)+2,[2+i 2+n+i]) = [0.5 -0.5];
  c(count+3*(i-1)+[1:3],1) = [0;0;1];
end
K.q = 3*ones(n,1);

count = 4*n + 1 + 3*n;
% second sdp constraint
c(count + [1:4*n^2],1) = reshape([speye(n) sparse(n,n);sparse(n,n) M],4*n^2,1);
for i = 1:n
  E = sparse(n,n);
  E(i,i) = -1;
  At(count + [1:4*n^2], 2+n+i) = reshape([sparse(n,n) E;E sparse(n,n)],4*n^2,1);
end

count = 4*n + 1 + 3*n + 4*n^2;
% first sdp constraint
c(count + [1:4*n^2],1) = reshape([speye(n) sparse(n,n);sparse(n,n) sparse(n,n)],4*n^2,1);
At(count + [1:4*n^2],1) = -reshape([sparse(n,2*n);sparse(n,n) speye(n)],4*n^2,1);
for i = 1:n
  E = sparse(n,n);
  E(:,i) = -C(:,i);
  At(count + [1:4*n^2], 2+i) = reshape([sparse(n,n) E;E' sparse(n,n)],4*n^2,1);
end
K.s = [2*n;2*n];
b = [-1 sparse(1,1+2*n)];

tic
[x,y] = sedumi(At,b,c,K);
time = toc;

X = diag(y(3:2+n)/y(2));
t = y(2);
answer = cond(X*M*X);

