error in objective function of fmincon and solver stopped prematurely

조회 수: 8 (최근 30일)
arina ariff
arina ariff 2014년 6월 1일
답변: Alan Weiss 2014년 6월 2일
this is my coding
function [x,fval,flag] = minim
x0 = [0.5, 0.5, -0.5];
lb = [-1, -1, -1];
ub = [1, 1, 1];
visc = 0.001;
dens = 1000;
w = 0.5;
opts = optimset('Display','iter','Algorithm','interior-point');
[x,fval,flag] = fmincon(@phenol,x0,[],[],[],[],lb,ub,@constraints,opts);
function J = phenol(x)
% x1 = flowrate, x2 = voidage, x3 = particles diameter
f1 = (0.778 + 0.0433*(x(1)) + 0.0196*(x(2)) - 0.1111*(x(3))); %efficiency
f2 = ((150*visc*((1-(x(2)))^2)*(x(1))/(((x(2))^3)*((x(3))^2))) + (1.75*(1-(x(2)))*dens*((x(1))^2)/(((x(2))^3)*(x(3))))); %pressure drop using Ergun equation
J = w*f1 + (w-1)*f2; %weightage
end % end of phenol
function [c, ceq] = constraints (x)
Pdrop = ((150*visc*((1-(x(2)))^2)*(x(1))/(((x(2))^3)*((x(3))^2))) + (1.75*(1- (x(2)))*dens*((x(1))^2)/(((x(2))^3)*(x(3)))));
c = Pdrop - 58.9; %pressure must < 58.9 bar
ceq = []; % no values assigned for linear equalities
end % end of constraints
end % end of minim
when i tried run the data it iterate but end with a message saying
"Solver stopped prematurely. fmincon stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 3000 (the default value)"
and before this when the x0 = [-0.5, 0, 0] it says error in objective function. please kindly help :)

답변 (2개)

Star Strider
Star Strider 2014년 6월 1일
To solve the ‘MaxFunEvals’ problem, change your optimset arguments to:
opts = optimset('Display','iter','Algorithm','interior-point', 'MaxIter', 10000, 'MaxFunEvals', 10000);
I didn’t run your code, but since x(2) (and x(3) if I’ reading your code correctly) appear in the denominator of some of your statements in ‘phenol’, they cannot allowed to be zero. Instead of: x0=[-5,0,0] change the zeros to small numbers, for example 1E-10, so:
x0 = [-5, 1E-10, 1E-10];
should solve that problem.
  댓글 수: 7
Star Strider
Star Strider 2014년 6월 1일
Thanks, Matt.
I didn’t pick up on the effects of poorly-defined constraints on fmincon performance.
Matt J
Matt J 2014년 6월 1일
I get successful termination with the following. It wasn't enough just to modify x0 and the lower bounds. I also had to set MaxFunEvals and MaxIter to Inf. Apparently, it's just a poorly conditioned problem with slow asymptotic convergence.
x0 = [0.5, 0.5, 0.5];
lb = [0,0,0];
ub = [1, 1, 1];
visc = 0.001;
dens = 1000;
w = 0.5;
opts = optimset('Display','iter','Algorithm','sqp',...
'MaxFunEval',inf,'MaxIter',Inf);
[x,fval,flag] = fmincon(@phenol,x0,[],[],[],[],lb,ub,@constraints,opts);

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


Alan Weiss
Alan Weiss 2014년 6월 2일
I wonder if you have an error in this line:
J = w*f1 + (w-1)*f2; %weightage
Did you mean this instead?
J = w*f1 + (1-w)*f2; %weightage
Also, the reason that you had trouble with the initial condition
x0 = [-0.5, 0, 0]
is this line from Pdrop:
...dens*((x(1))^2)/(((x(2))^3)*(x(3)))));
If x(2) and x(3) are zero, then you get a division by zero here.
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

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