Global Optimizationproblem using Global Search
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, i am trying to use the globalSearch function to solve the following Optimization Problem:
min - x(3)
s.t. -x(1) -x(2) <= 0
-10*x(1)+x(1)^2-4*x(2)+x(2)^2+x(3) <= 0
3x(1) + x(2) <= 12
2x(1) + x(2) <= 9
x(1) + 2x(2) <= 12
x(1), x(2) >= 0
If you try a bit out you see that x(1) = 4, x(2) = 0, x(3) = 24 is the optimal solution.
But my Matlab Code gives a different solution and i do not know why.
Here my Code:
f=@(x)-x(3);
x0 = [0,0,0];
lb = [0,0,-Inf];
gs = GlobalSearch;
A = [-1 -1 0;
3 1 0;
2 1 0;
1 2 0];
b = [0; 12; 9; 12];
nonlincon = @constr;
problem = createOptimProblem('fmincon','x0',x0,'objective',f,'lb',lb,'Aineq',A,'bineq',b,'nonlcon',nonlincon)
x = run(gs,problem)
I would be thankful if someone could tell me if I did a mistake somewhere.
댓글 수: 7
Torsten
2022년 1월 8일
function main
f=@(x)-x(3);
x0 = [0,0,0];
lb = [0,0,-Inf];
A = [-1 -1 0;
3 1 0;
2 1 0;
1 2 0];
b = [0; 12; 9; 12];
nonlcon = @constr;
sol = fmincon (f, x0, A, b, [], [], lb, [], nonlcon)
end
function [c,ceq] = constr(x)
c = -10*x(1)+x(1)^2-4*x(2)+x(2)^2+x(3);
ceq = [];
end
채택된 답변
Matt J
2022년 1월 8일
We can verify that Torsten's solution is feasible as below. Since it gives a better objective function value than your experimental solution, your solution cannot be the correct one.
A = [-1 -1 0;
3 1 0;
2 1 0;
1 2 0];
b = [0; 12; 9; 12];
constr = @(x) -10*x(1)+x(1)^2-4*x(2)+x(2)^2+x(3);
x=[3.5000 1.5000 26.5000]';
b-A*x
constr(x)
댓글 수: 6
추가 답변 (1개)
Matt J
2022년 1월 8일
편집: Matt J
2022년 1월 8일
In fact, the problem can also be solved with quadprog, since it is equivalent to,
min -10*x(1)+x(1)^2-4*x(2)+x(2)^2
s.t.
3x(1) + x(2) <= 12
2x(1) + x(2) <= 9
x(1) + 2x(2) <= 12
x(1), x(2) >= 0
and since the objective function of the reformulated problem is srictly convex, it establishes that the solution is also unique:
f=@(x)-x(3);
x0 = [0,0,0];
lb = [0,0];
A =[3 1;
2 1;
1 2];
b = [12; 9; 12];
H=2*eye(2);
f=[-10;-4];
[x12,x3]=quadprog(H,f,A,b,[],[]);
x=[x12;-x3]'
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!