MATLAB: Solution of mincon doesn’t satisfy the nonlcon constraints

nonlcon equation not satisfied

Hello together,
I calculated a nonlinear programm with fmincon, where the nonlcon constraints function is included:
function f = objfun(x)
f = - ((30*x(1) + 15*x(2))^2)
end
[c,ceq] = nlcon(x)
c = x(1)^2 + 2*x(2)^2 - 540;
ceq = (x(1)^0.5) + (x(2)^0.5)-10;
end
x0 = [1,1]
A = [0 1]
b = [40]
lb = [0 0]
ub = [10000 10000]
[x,fval] = fmincon('objfun',x0,A,b,[],[],[lb],[ub],'nlcon')
The solution for x1 = 17.35 and x2 = 10.9305 doesn't satisfy the ceq equation (x1^0.5 + x2^0.5 =10 –> our value is somewhere between 7 and 8)
fval is – 46.852.
Do you have an idea what we can improve to satisfy the equation? Thanks in advance.

Best Answer

function main
x0 = [1,1]
A = [0 1]
b = [40]
lb = [0 0]
ub = [10000 10000]
[x,fval] = fmincon(@objfun,x0,A,b,[],[],lb,ub,@nlcon)
end
function f = objfun(x)
f = - ((30*x(1) + 15*x(2))^2)
end
function [c,ceq] = nlcon(x)
c(1) = x(1)^2 + 2*x(2)^2 - 540;
ceq(1) = (x(1)^0.5) + (x(2)^0.5)-10;
end