필터 지우기
필터 지우기

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
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에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by