Problem of erf when using fmincon

3 次查看(过去 30 天)
Max Wang
Max Wang 2020-5-15
评论: Max Wang 2020-5-15
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.
clear all
x2=rand(2,1);
x1=x2+rand(2,1);
x0=[x1;x2];
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.
A=[-A0; A0];
b = [zeros(2,1);ones(2,1)];
Aeq=[];
beq=[];
lb=zeros(4,1);
ub=[];
options = optimoptions('fmincon','Display','iter','Algorithm','sqp','TolFun',1e-10);
xsol= fmincon(fun,x0,A,b,Aeq,beq,lb,ub,[],options);
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.

回答(1 个)

Are Mjaavatten
Are Mjaavatten 2020-5-15
Your problem has infinitely many solutions. Whenver x(1)-x(3) = 1 and x(2)-x(4) = 1, fun = 0, which is the minimum value possible.
That said, fmincon obviously searches beyond the constraints in your case. I wrote your 'fun' function as an ordinary function in order to see the offending x vector in the debugger, and you are absolutely right. The program crashes when:
K>> x
x =
1.762231198224400
0.964095464916107
0.762231171965109
0
K>> A*x-b
ans =
-1.000000026259291
-0.964095464916107
0.000000026259291 % Should be <= 0!!
-0.035904535083893
This may have to do with the lack of a unique solution, but anyway I think the Matworks staff should look into this.
  1 个评论
Max Wang
Max Wang 2020-5-15
Thank you for your reply. It is a toy version of the problem and I just used it to test erf in the objective funtion, so there may be many trivial solutions (but fmincon cannot find any).
I assume fmincon is not expected to search outside the feasible region? I tried several algorithms and all throw this kind of error.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by