m = 50;
n = 20;
randn('state',0);
rand('state',0);
A0 = randn(m,n);
[U,S,V] = svd(A0);
S= diag(fliplr(logspace(-0.7,1,n)));
A0 = U(:,1:n)*S*V';
A1 = randn(m,n); A1 = A1/norm(A1);
A2 = randn(m,n); A2 = A2/norm(A2);
Aperb0 = [A1;A2];
p = 2;
b = U(:,1:n)*randn(n,1) + .1*randn(m,1);
xnom = A0\b;
delta = .1;
xtych = [A0; sqrt(delta)*eye(n)] \ [b; zeros(n,1)];
cvx_begin sdp quiet
variables t lambda xrob(n)
minimize(t+lambda)
subject to
[eye(m) A1*xrob A2*xrob A0*xrob-b; ...
[A1*xrob A2*xrob]' lambda*eye(2) zeros(2,1); ...
[A0*xrob-b]' zeros(1,2) t] >= 0;
cvx_end
notrials=100000;
r = sqrt(rand(notrials,1));
theta = 2*pi*rand(notrials,1);
v = [r.*cos(theta) r.*sin(theta)];
ls_res = zeros(1,notrials);
rob2_res = zeros(1,notrials);
rob_res = zeros(1,notrials);
tych_res = zeros(1,notrials);
for i =1:notrials
A = A0 + v(i,1)*A1 + v(i,2)*A2;
ls_res(i) = norm(A*xnom-b);
rob_res(i) = norm(A*xrob-b);
tych_res(i) = norm(A*xtych-b);
end;
figure
[N1, hist1] = hist(ls_res,[min(ls_res):.1:max(ls_res)]);
freq1 = N1/notrials;
[N2, hist2] = hist(rob_res,hist1);
freq2 = N2/notrials;
[N3, hist3] = hist(tych_res,hist1);
freq3 = N3/notrials;
h = bar(hist3,freq3);
text(3, 0.07, 'Tikhonov');
set(h,'FaceColor',0.90*[1 1 1]);
hold on
h = bar(hist2,freq2);
text(4.2, 0.05, 'Nominal');
set(h,'FaceColor',0.80*[1 1 1]);
h = bar(hist2,freq2);
set(h,'FaceColor','none');
text(2.6, 0.2, 'Robust LS');
h = bar(hist3,freq3);
set(h,'FaceColor','none');
h = bar(hist1,freq1);
set(h,'FaceColor','none');
xlabel('||(A0 + u1*A1 + u2*A2)*x - b||_2')
ylabel('Frequency')
hold off