MATLAB Answers

Problem of erf when using fmincon

2 ビュー (過去 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
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)];
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 =
K>> A*x-b
ans =
0.000000026259291 % Should be <= 0!!
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.



Community Treasure Hunt

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

Start Hunting!

Translated by