Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

what cause fmincon stop prematurely

Asked by rio novendra

rio novendra (view profile)

on 16 May 2013

I have a constrained minimization problem with objective function (in simplified form)

z=b1+p1*log(p1/(p1+p2+p3))+b2+p2*log(p2/(p1+p2+p3))+b3+p3*log(p3/(p1+p2+p3))
where 
b1=a1*2,%(a1 is a constant input)
b2=a2*3,%(a2 is a constant input)
b3=a3*4,%(a3 is a constant input)
and constraints
2*p1+3*p2=A1,%(A1 is a constant input)
3*p2+5*p3=A2,%(A2 is a constant input)
p1>=0,
p2>=0,
p3>=0,
so, I wrote on my script 
a1=input('a1=');
a2=input('a2=');
a3=input('a3=');
A1=input('A1=');
A2=input('A2=');
A=[-1,0,0;0,-1,0,0;0,0,-1];B=[0;0;0];Aeq=[2,3,0;0,3,5];Beq=[A1;A2];
optimal_p1p2p3=fmincon(@fozw,[0.1;0.1;0.1],A,B,Aeq,Beq);
function z=fozw(w);
p1=w(1);p2=w(2);p3=w(3);
z=b1+p1*log(p1/(p1+p2+p3))+b2+p2*log(p2/(p1+p2+p3))+b3+p3*log(p3/(p1+p2+p3));
end
end
Then, when I run the script. It  appeared on command window 
solver has stop prematurely
fmincon stop because it exceeded function evaluation limit
optimal_p1p2p3=
NaN
NaN
NaN

What is the possible error?.

rio novendra

rio novendra (view profile)

Products

No products are associated with this question.

1 Answer

Answer by Alan Weiss

Alan Weiss (view profile)

on 17 May 2013
Accepted answer

Your function has logarithms and division. It seems to me quite likely that fmincon steps into a region where the function is undefined, and cannot proceed.

I suggest that you do two things:

  • Ensure that your initial point x0 evaluates to a finite value.
  • Use the interior-point algorithm, which is robust to occasional evaluation failures.

Good luck,

Alan Weiss

MATLAB mathematical toolbox documentation

0 Comments

Alan Weiss

Alan Weiss (view profile)

Contact us