Hello, I am using fmincon to solve a problem whose objective function involves erf and sqrt. Although I have added constraints, I still got the error message
"Error using erf
Input must be real and full."
The toy code is as follows.
fun = @(x)sum( erf(sqrt(-log(x(1:2)-x(3:4)))));
A0 = [eye(2) -eye(2)];
% the constraint below makes sure -log(x(1:2)-x(3:4)) is always a nonnegative vector.
b = [zeros(2,1);ones(2,1)];
options = optimoptions('fmincon','Display','iter','Algorithm','sqp','TolFun',1e-10);
If I remove erf from the objective function, i.e., fun = @(x)sum( (sqrt(-log(x(1:2)-x(3:4))))), I don't have this error.
Since erf complains, it maens sqrt gives complex values, but why is this possible given the constraint? Could anyone help? Thank you.