MATLAB: Two linear equation with absolute value equation

equationnonlinear

Hello,
I have two linear equation and one absolute value equation. Is there a easy way to obtain minimum norm solution ?

Best Answer

Correct minimum norm solution is
xmin =
90.0000
-40.0000
5.0000
5.0000
normxmin =
98.7421
obtained with this code
s = cell(1,4);
[s{:}] = ndgrid([-1 1]);
s = reshape(cat(5,s{:}),[],4);
fmin = Inf;
xmin = nan(4,1);
for k=1:size(s,1)
sk = s(k,:);
Aeq = [1 1 -1 -1;
1 1 1 1;
sk.*[1 1 -1 -1]];
beq = [40; 60; 120];
A = -diag(sk);
b = zeros(4,1);
[x,f,flag] = quadprog(eye(4), zeros(4,1), ...
A, b, ...
Aeq, beq, ...
[], []);
if flag > 0 && f < fmin
fmin = f;
xmin = x;
end
end
xmin
normxmin = norm(xmin,2)
% Check the constraints
xmin(1)+xmin(2)-xmin(3)-xmin(4)
xmin(1)+xmin(2)+xmin(3)+xmin(4)
abs(xmin(1))+abs(xmin(2))-abs(xmin(3))-abs(xmin(4))