Linear constraints not satisfied during optimization using fmincon
이전 댓글 표시
Hi, I am relatively new to optimization and I am trying to optimize a nonlinear cost function with linear constraints. Using fmincon the optimization completes after a few iterations but the ans I recieved for my variables doesnt satisfy the constraints.
Optimization function
function [x, fval, iter] = myrun
x0 = [800;350;200;250];
A = [-1 -1 -1 -1;
1 1 1 1;
-0.59 -15.44 -7.12 -0.62;
-79.77 0 0 -16.15;
-6.65 -59.1 -25.94 -4];
b = [1360;
2268;
70;
560;
114.3];
Aeq = [];
beq = [];
lb = [360,250,150,120];
ub = [1080,500,300,360];
options = optimoptions(@fmincon,'Display','iter');
[x,fval,exitflag, output] = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@nlcon,options);
end
and my objective function is
function f = myfun(x)
f = (0.0114*x(1)+0.01032*x(2)+0.0228*x(3)+0.0081*x(4))+15*((log(0.0114*x(1)))+(log(0.01032*x(2)))+(log(0.0228*x(3)))+(log(0.0081*x(4))));
end
댓글 수: 3
John D'Errico
2022년 4월 9일
When you post a PICTURE of the code you wrote, anyone who might be tempted to help you must then retype your code from the picture.
If you paste in the TEXT of your code, then they can copy it, and then paste it directly into MATLAB. It is easier for you to paste in your code too. In this case, it becomes far easier for someone to offer to help you.
So is there a good reason why you want to make it more difficult to get help on your homework problem?
MOHAMMAD BAWANY
2022년 4월 9일
John D'Errico
2022년 4월 9일
And now I can actually look at your question.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Choose a Solver에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!