Fmincon - error using barrier
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
Walter Roberson
am 3 Mai 2016
I happen to hit this earlier this morning. Your initial function call to the objective function returns inf or nan.
2 Kommentare
Walter Roberson
am 4 Mai 2016
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.
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!