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)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1×2
4.0000 359.9999
fval = -6.5200
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)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1×2
4.0000 359.9999
fval = -6.5200
Maybe i should try another function? or i was doing something wrong?

2 commentaires

Torsten
Torsten le 6 Juin 2022
Modifié(e) : Torsten le 6 Juin 2022
It's the unique minimum of the function to be minimized.
So the solution does not change when you change the initial guess.
By the way: Your problem is a linear optimization problem. You should use "linprog" to solve.
There is one additional constraint thats why i thought about using initial point. The constraint its Cb=0.5 (Ca=Cb). Where
0=((1-Ca)*F/W)-k1*Ca
and
0=((-Cb*F)/W)+(k1*Ca)-(k2*Cb).
W=[0:0.1:100], k1=9000, k2=35000
So probably if i need to use linprog i need to transform equation so i will put initial point in it?

Connectez-vous pour commenter.

 Réponse acceptée

Matt J
Matt J le 6 Juin 2022

1 vote

It looks like there are supposed to be some additional, more interesting constraints. Otherwise, if you have only bounds, the minimization of a linear function is trivial and can be done by inspection. You don't need any fancy iterative solvers.

3 commentaires

There is one additional constraint thats why i thought about using initial point. The constraint its Cb=0.5 (Ca=Cb). Where
0=((1-Ca)*F/W)-k1*Ca
and
0=((-Cb*F)/W)+(k1*Ca)-(k2*Cb).
W=[0:0.1:100], k1=9000, k2=35000
also i tried now with linprog but in this case i cant use initial point
f = [1 -0.007];
% 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] = linprog(-f, A, b, Aeq, beq, lb, ub)
Optimal solution found.
x = 2×1
4 300
fval = -1.9000
Matt J
Matt J le 6 Juin 2022
Modifié(e) : Matt J le 6 Juin 2022
As you can see, linprog is giving you the same solution as fmincon. The reason is that there is again only a unqiue and trivial solution. If you have additional constraints, you should incorporate them.
fun = @(x) -x(1)+0.007*(+x(2));
lb = [0, 300];
ub = [4, 360];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [0, 300];
[x, fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1×2
4.0000 300.0001
fval = -1.9000
Torsten
Torsten le 7 Juin 2022
Modifié(e) : Torsten le 7 Juin 2022
Your additional constraints are not clear to me, especially what the unknowns are and what they have to do with x(1) and x(2).

Connectez-vous pour commenter.

Plus de réponses (1)

Sam Chak
Sam Chak le 7 Juin 2022
Modifié(e) : Sam Chak le 7 Juin 2022
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 commentaires

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),
x = 1×2
4 300
Sam Chak
Sam Chak le 7 Juin 2022
Thanks @Matt J. Learned a simpler approach today. 👍

Connectez-vous pour commenter.

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by