MATLAB: Problem regarding fmincon solver

fminconMATLABoptimizationOptimization Toolboxsolve

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.

Best Answer

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];