Two linear equation with absolute value equation

조회 수: 3 (최근 30일)
Murat YAPICI
Murat YAPICI 2021년 1월 13일
댓글: Murat YAPICI 2021년 1월 13일
Hello,
I have two linear equation and one absolute value equation. Is there a easy way to obtain minimum norm solution ?

채택된 답변

Bruno Luong
Bruno Luong 2021년 1월 13일
편집: Bruno Luong 2021년 1월 13일
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))

추가 답변 (1개)

Alan Stevens
Alan Stevens 2021년 1월 13일
Do you mean something like this
X0 = [-50 -5];
[X, Fval] = fminsearch(@(X) fn(X),X0);
x2 = X(1); x1 = 50-x2;
x4 = X(2); x3 = 10-x4;
disp([x1 x2 x3 x4])
disp(x1+x2+x3+x4)
disp(x1+x2-x3-x4)
disp(abs(x1)+abs(x2)-abs(x3)-abs(x4))
function F = fn(X)
x2 = X(1); x1 = 50-x2;
x4 = X(2); x3 = 10-x4;
F = norm(abs(x1)+abs(x2)-abs(x3)-abs(x4)-120);
end
  댓글 수: 1
Murat YAPICI
Murat YAPICI 2021년 1월 13일
Thank you for your answer.
I mean something like this but I want to minimize (Like pseudo inverse). Not .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by