Problem of erf when using fmincon
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!