Fmincon - error using barrier

조회 수: 12 (최근 30일)
charlotte88
charlotte88 2016년 5월 3일
댓글: Walter Roberson 2016년 5월 4일
Hi,
I have a maximization problem that I want to solve using matlab. I have previously worked without logs, and the code works perfectly well. However, when I introduce log, I get the following error:
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 797)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in max_sol_ln (line 13)
a = fmincon(@(x)maximizationpb2_ln(x,alpha(k)),x0,A,b,Aeq,beq,lb,ub);
My code is as follows:
function b = maximizationpb2_ln(x, alpha)
beta1 = 6;
beta2 = 6;
s1 = 1/3;
s2 = 1/3;
s3 = 1/3;
b = -((log(x(1))) - beta1*((x(2)-s2)^2+(1-x(1)-x(2)-s3)^2))^(1-alpha) * ((log(x(2))) - beta2*((x(1)-s1)^2+(1-x(1)-x(2)-s3)^2))^alpha;
and
lb = [0,0];
ub = [1,1];
A = [1,1];
b = [1];
Aeq = [];
beq = [];
x0 = [1/3, 1/3];
for k=1:11
alpha(k)=0.05*(k-1);
a = fmincon(@(x)maximizationpb2_ln(x,alpha(k)),x0,A,b,Aeq,beq,lb,ub);
M(k,1)=a(1);
M(k,2)=a(2);
M(k,3)= 1 - a(1) - a(2);
end
plot(alpha,M(:,1)) % plot a(1) over alpha
plot(alpha,M(:,2)) % plot a(2) over alpha
plot(alpha,M(:,3)) % plot a(3) over alpha
Any help would be very much appreciated!

답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 3일
I happen to hit this earlier this morning. Your initial function call to the objective function returns inf or nan.
  댓글 수: 2
charlotte88
charlotte88 2016년 5월 3일
Yes, I guess you are right... Is there a way to go come around that?
Walter Roberson
Walter Roberson 2016년 5월 4일
I worked through the algebra. Except when alpha = 0, you are raising negative values to a fraction, which is going to give a complex result. But you are multiplying two such complex results together, and the result is going to always be algebraically real-valued. But because of numeric round-off you are sometimes ending up with a small imaginary part that can be neglected. Take real(b) to avoid that.
You are getting infinities if x(1) or x(2) are 0, because of the log() terms. The only way to avoid that is to use a lower bound that is greater than 0, such as realmin.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by