フィルターのクリア

Help with 'fmincon' fucntion for optimsation

2 ビュー (過去 30 日間)
Shemin Sagaria
Shemin Sagaria 2022 年 10 月 5 日
コメント済み: Shemin Sagaria 2022 年 10 月 6 日
Hi,
I am trying to find the minimum value of the function with fmincon, but i need some help. My code is written here.
clc
m = 8;
a =[.75,0.75,0.85,0.8];
x0 = [0,0,0,0];
lb = [0,0,0,0];
ub = [5,2,4,5];
nonlincon = @nlcon;
objective = @(x) (x(1)*a(1))+(x(2)*a(2))+(x(3)*x(3))+(x(4)*a(4));
[i,fval] = fmincon(objective,x0,[],[],[],[],lb,ub,nonlincon);
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.
disp(i)
4.2066 1.4184 0.3750 0.0000
fval
fval = 4.3594
function [c,ceq] = nlcon(x)
c = [];
ceq = sum(x)-6;
end
  1. I need to include the variable (m) into nlcon fucntion and use it instead of 6. I tried different ways and its not working. I hope some of you can help me with this.
  2. The minimum value from the program is wrong. If you multiply (x*a), you would see fval = 4.53. But the result shows 4.359. Also the minimum possible fval = 4.5, when x1 = 4.5 and x2 = 1.5. How can i make this correct?
I really appreciate your help on this one. Thank you in advance :).

採用された回答

Torsten
Torsten 2022 年 10 月 5 日
編集済み: Torsten 2022 年 10 月 5 日
Your problem is linear. You might want to try "linprog" instead of "fmincon".
m = 6;
a =[.75,0.75,0.85,0.8];
x0 = [0,0,0,0];
lb = [0,0,0,0];
ub = [5,2,4,5];
Aeq = [1 1 1 1];
beq = m;
objective = @(x) (x(1)*a(1))+(x(2)*a(2))+(x(3)*a(3))+(x(4)*a(4));
[i,fval] = fmincon(objective,x0,[],[],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.
i = 1×4
4.3430 1.6570 0.0000 0.0000
fval = 4.5000
  1 件のコメント
Shemin Sagaria
Shemin Sagaria 2022 年 10 月 6 日
Thank you very much ;)

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by