Help with 'fmincon' fucntion for optimsation
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shemin Sagaria
am 5 Okt. 2022
Kommentiert: Shemin Sagaria
am 6 Okt. 2022
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);
disp(i)
fval
function [c,ceq] = nlcon(x)
c = [];
ceq = sum(x)-6;
end
- 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.
- 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 :).
0 Kommentare
Akzeptierte Antwort
Torsten
am 5 Okt. 2022
Bearbeitet: Torsten
am 5 Okt. 2022
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)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!