Linear constraints not satisfied during optimization using fmincon
Show older comments
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 Comments
John D'Errico
on 9 Apr 2022
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
on 9 Apr 2022
John D'Errico
on 9 Apr 2022
And now I can actually look at your question.
Accepted Answer
More Answers (0)
Categories
Find more on Choose a Solver in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!