I'm trying to solve a non-liner optimization problem with a non-liner constraint by applying fmincon function in matlab. However, I got the following error: "Failure in initial user-supplied nonlinear constraint function evaluation. FMINCON cannot continue." I checked on the web a lot but I couldn't fixed it. It seams that it is a very general error message. I made my problem very small with just 3 variables, still I get the same result. here are my functions:
function main()
global x
global y
y(2)=15;
y(3)=15;
a=[0.01;0.05];
opts = optimoptions(@fmincon,'Algorithm','interior-point')
[x,fval] = fmincon(@objfun,a,[],[],[],[],0.01,1,@mycon,opts)
y(1)=x(2)*y(2)+x(3)*y(3);
x
y
fval
end
where
function [c,ceq ] = mycon( x )
c=-(x(3)*y(3)+x(2)*y(2))*x(1)+5;
ceq=[];
end
and
function fun = objfun( x )
fun=@(x)(x(2)*y(2)+x(3)*y(3))*(1+(1/x(1)-1)+x(1))+y(2)*(1+ (1/x(2)-1)+x(2))+y(3)*(1+(1/x(3)-1)+x(3));
end