Least-square with 2-norm constraint

by

 

Minimize |A*x-b|^2 such that |x| = cte

spherelsq_demo.m
% Data
n=2;
m=4;
A=rand(m,n);
b=rand(m,1);
xnorm = 2;

% solution
xopt = spherelsq(A,b,xnorm);

% Check
theta=linspace(-pi,pi,100);
% Generate 100 vectors such that |x|=xnorm
X=xnorm*[cos(theta); sin(theta)];
R=bsxfun(@minus,A*X,b);
r=sum(R.^2,1); % r = J(x)

% Graphic
figure(1); clf
plot(theta,r);
ax = axis;
hold on;
ttopt=atan2(xopt(2),xopt(1));
plot(ttopt+[0 0], ax([3 4]), 'r');

Contact us