Failure in initial objective function evaluation. FMINCON cannot continue
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I want to find the minimum of cost rate in the following code, but I get error.
%%%%%%%%%%%%%%%%%%% optimization part%%%%%%%%%%
x0=[10,10,2]; % Starting guess
lb=[1,1,1];
ub=[30,30,4];
%options=optimset('outputfcn',@outfun,'Largescale','off','Algorithm','interior-point','Display','iter','Tolx',1e-15,'Tolfun',1e-16,'MaxFunEvals',600,'MaxIter',100);
options = optimoptions('fmincon','Display','iter-detailed','Algorithm','interior-point','PlotFcn',{@optimplotx,...
@optimplotfval,@optimplotfirstorderopt},'Tolx',1e-10,'Tolfun',1e-4,'MaxFunEvals',600,'MaxIter',100);
[x,fval,exitflag,output]=fmincon(@optim,x0,[],[],[],[],lb,ub,[],options)
function fq=optim(x)
clc;
clear all;
format compact;
alpha1=5; beta1=0.8;
alpha2=1; beta2=4;
CI=58; CR=2000; CP=1000;
T=20; % time horizon
H=30; % failure threshold
N=1000; % number of observation
M=2; % number of units
p=T/N; t=(0:p:T);
g=zeros(M,N+1); G=zeros(M,N+1);
for i=1:N
g(1,i)=gamrnd(alpha1*p,beta1);
G(1,i+1)=G(1,i)+g(1,i);
g(2,i)=gamrnd(alpha2*p,beta2);
G(2,i+1)=G(2,i)+g(2,i);
end
Inspection=2;
tau=Inspection*(1000/20);
u1=G(1,tau)
u2=G(2,tau)
if u1<x(1)
if u2<x(2)
%x(1) is for H2 component 1, X(2) is for H2 component 2, and X(3) is for
totalcost=(CI+CR*norep(x(1),x(2),x(3),u1,u2)+CP*(downtime(x(3),u1,u2)))/x(3);
fq=totalcost;
else
u2=0;
totalcost=(CI+CR*norep(x(1),x(2),x(3),u1,u2)+CP*(downtime(x(3),u1,u2)))/x(3);
fq=totalcost;
end
u1=0;
u2=0;
totalcost=(CI+CR*norep(x(1),x(2),x(3),u1,u2)+CP*(downtime(x(3),u1,u2)))/x(3);
fq=totalcost;
end
end
In my code downtime and norep is a defined function. I will get the following error.
Reference to a cleared variable x.
Error in model>optim (line 35)
if u1<x(1)
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in model (line 10)
[x,fval,exitflag,output]=fmincon(@optim,x0,[],[],[],[],lb,ub,[],options)
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
1 comentario
dpb
el 19 de Nov. de 2018
Your function contains...
function fq=optim(x)
clc;
clear all;
which just wiped out x that you passed it.
There is absolutely no reason for either of those in any function, start by deleting those and then test your function itself first.
Respuestas (0)
Ver también
Categorías
Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!