Is there a way to include these implicit constraint variables (u1,u2,u3) as the optimization variables x1,x2,x3 so that fmincon evaluate them without solving the nonlinear system by fsolve?
That really is what you should be doing and that's mostly all there is to say. Just rewrite your problem in terms of the longer vector of unknown design variables z=[x(:);u(:)]. This means, for example, that you'll need to add columns of zeros to your linear constraint matrices corresponding to the new variables, u. This is equivalent to saying that the u(i) don't really participate in the linear constraints.
In your mycon function, you can extract z into separate pieces x and u for your convenience. Then use the ceq output to enforce your system of nonlinear equations:
function [c, ceq]=mycon(z)
x=z(1:N);
u=z(N+1:end);
ceq(1)=x(1)^2+log(u(1))+sqrt(u(3));
ceq(2)=x(2)^2+x(3)+log(u(2));
ceq(3)=sqrt(x(1))+x(3)+u(1);
ceq(4)=x(2)+x(1)+u(2)^2;
ceq(5)=x(1)^2+x(2)+log(u(3));
ceq(6)=x(1)^2+x(3)+log(u(1));
c=[];
As for
you should clarify why you are allowing u(i) to take on complex values. I'm guessing it's because fsolve isn't able to avoid complex solutions for u and that what you really want is,
Once you abandon fsolve, and recode everything in terms of z, you can simply enforce these bounds using the lb,ub fmincon input arguments. Note that fmincon's sqp algorithm will enforce bounds so that expressions like ln(u), sqrt(u) never give complex values. You should also be returning NaN or Inf from the objective or constraints for inputs z that don't give real and well-defined values. SQP can recover from NaNs and Infs during the search.
Finally, you should be careful with non-differentiable expressions like sqrt(u). Here, it might be okay, because you are bounding u away from u=0 where sqrt(u) is non-differentiable. Otherwise, though, you need to take differentiability issues into consideration. Options might be to rewrite
as
Or you can consider changes of variables like y=sqrt(u) so that all expressions are written smoothly in terms of y.
Best Answer