I’m trying to minimize a trace function subject to a norm constraint. Here’s my code in Matlab:
function q=min_prob(y,t)
sz1=size(y,1);
sz2=size(y,2);
for i=1:10
cvx_begin sdp quiet
cvx_precision low
variable z(sz1,sz2)
minimize(trace(y'*z))
subject to
norm(grad2(z,sz1,sz2),1)<=t;
cvx_end
end
end
function y=grad2(x,sz1,sz2)
x=reshape(x,sz1,sz2);
% d1=[x(1,:);diff(x,1,1)];
% d2=[x(:,1)';diff(x,1,2)']';
d1=zeros(sz1,sz2);
d2=zeros(sz1,sz2);
d1(1,:)=x(1,:);
d2(:,1)=x(:,1);
for i=1:sz1-1
d1(i+1,:)=x(i+1,:)-x(i,:);
end
for i=1:sz2-1
d2(:,i+1)=x(:,i+1)-x(:,i);
end
y=d1+d2;
end
cvx doesn’t recognize the inbuilt ‘diff’ function, so I wrote out the function explicitly.
But when I run the code I get the following error in the grad2 function at d1(1,:)=x1(1,:)
: “Conversion to double from cvx is not possible”.
I’ve tried using expression z(sz1,sz2)
, it doesn’t work.