Problem with optimization using fmincon
Show older comments
I need to optimize function by finding the maximum of this function: J = F [kg/min] – 0,007 [kg/(min K)] * T [K], where F=[0:4], T=[300:360]. I think that its need to be done by using fmincon. I tried to use it but despite of changing starting point the result its not changing.
fun = @(x) -x(1)+0.007*(-x(2));
lb = [0, 300];
ub = [4, 360];
A = [];
b = [];
Aeq = [];
beq = [];
% x0 = (lb + ub)/2;
x0 = [0, 300];
% x0 = x0/5;
[x, fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
fun = @(x) -x(1)+0.007*(-x(2));
lb = [0, 300];
ub = [4, 360];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = (lb + ub)/2;
%x0 = [0, 300];
% x0 = x0/5;
[x, fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
Maybe i should try another function? or i was doing something wrong?
Accepted Answer
More Answers (1)
Sometimes, the optimization problem can be understood better if you can visualize the objective function:
If the function is merely a planar surface in this case, all you need to do is to inspect the 4 corners and find the maximum of this function.
[X, Y] = meshgrid(0:4/40:4, 300:60/40:360);
Z = X - 0.007*Y;
surf(X, Y, Z)

Also, the first equality constraint simplified to
0 = ((1 - 0.5)*F/W) - 9000*0.5
and the second equality constraint simplified to
0 = ((-0.5*F)/W) + (9000*0.5) - (35000*0.5)
where W is from 0 to 100. Since F is bounded in [0, 4], can you see a way to achieve that?
2 Comments
If the function is merely a planar surface in this case, all you need to do is to inspect the 4 corners and find the maximum of this function.
Even simpler, the planar function is additively separable into two 1D linear functions, f(x)= f1(x1)+f2(x2). So, for each of f1 and f2, it is enough to inspect just the 2 endpoints of their domains. This leads to the purely analytical solution,
f = -[1 -0.007];
lb = [0, 300];
ub = [4, 360];
x=lb;
x(f<0)=ub(f<0),
Categories
Find more on Solver Outputs and Iterative Display 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!