Problem regarding fmincon solver

18 visualizzazioni (ultimi 30 giorni)
Sudip Poddar
Sudip Poddar il 14 Ago 2020
Commentato: Sudip Poddar il 14 Ago 2020
Hi,
I am trying to learn fmincon. I am trying to run the following example code for the first time. But, failed to run it. Getting error.
function [c,ceq] = nlcon (w)
c1 = 12*w(1) + 0*w(2) + w(5)*w(3) - 7*w(4) - 0.5*w(4);
c2 = - 0.5*w(4) - 12*w(1) - 0*w(2) - w(5)*w(3) + 7*w(4);
c = [c1;c2]
ceq = w(1) + w(2) + w(3) - w(4);
end
objective = @(w) w(1) + w(2) + 2*w(3) + 0*w(4) + 0*w(5);
x0 = [0.0,0.0,0.0,0.0,0.0];
disp(["Initial objective:" num2str(objective(x0))])
[c,ceq] = nlcon(x0)
A = [];
b = [];
Aeq = [];
beq = [];
lb = [0.0;0.0;0.0;2.0;1.0];
ub = [4.0;4.0;3.0;4.0;12.0];
nonlincon = @nlcon;
[x,fval] = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,nonlincon)
But getting the error as follows:
܀error: Initial parameters violate constraints.
error: called from
__lm_feasible__ at line 92 column 5
fmincon at line 417 column 20
main at line 12 column 9
Could you please help me to solve this issue? Looking forward to your reply.

Risposta accettata

Walter Roberson
Walter Roberson il 14 Ago 2020
lb = [0.0;0.0;0.0;2.0;1.0];
ub = [4.0;4.0;3.0;4.0;12.0];
x0 = [0.0,0.0,0.0,0.0,0.0];
lb is lower bounds. Your second-last entry in lb is 2.0, so the second last entry in x0 must be at least 2.0, as in
x0 = [0.0,0.0,0.0,2.0,1.0];
  20 Commenti
Walter Roberson
Walter Roberson il 14 Ago 2020
ga() is not reliable for finding global minima.
Sudip Poddar
Sudip Poddar il 14 Ago 2020
Hi Walter,
Thanks a lot for providing the link. I will check ga. Thanks again.
Hi Matt,
I agree with you. I will check it also. Many thanks to you also.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by