Error while running fmincon

9 visualizaciones (últimos 30 días)
APRA LIPI
APRA LIPI el 25 de Sept. de 2019
Comentada: Matt J el 26 de Sept. de 2019
This is the main file and while running this I am getting the following error:
clear all
close all
clc
global SP HCD PC HCS TC Dp
SP=[9.39,16.57,14.05];
HCD=[1,1,1];
PC=[1.2,1.2,1];
HCS=[0.12,0.12,0.10];
TC=[2,1,1,2,1,1,2,1,1];
Dp=0.4;
Q0= zeros(21,1); % Starting guess
A=[];
b=[];
Aeq=[];
beq=[];
OF= @Objective;
Cons=[];
lb = zeros;
ub = Inf;
Q = fmincon(OF,Q0,A,b,Aeq,beq,lb,ub,Cons);
disp(Q)
disp(['Final Objective:' num2str(OF(Q))])
The error is as follows:
Warning: Length of lower bounds is < length(x); filling in missing
lower bounds with -Inf.
> In checkbounds (line 33)
In fmincon (line 324)
In Main (line 20)
Warning: Length of upper bounds is < length(x); filling in missing
upper bounds with +Inf.
> In checkbounds (line 47)
In fmincon (line 324)
In Main (line 20)
Error using fmincon (line 700)
FMINCON requires all values returned by functions to be of data type
double.
Error in Main (line 20)
Q = fmincon(OF,Q0,A,b,Aeq,beq,lb,ub,Cons);
>>
Please tell how to correct the error.

Respuestas (1)

Matt J
Matt J el 25 de Sept. de 2019
Editada: Matt J el 25 de Sept. de 2019
The size of lb(:) and ub(:) must be the same as Q0(:).
lb = zeros(21,1);
ub = Inf(21,1);
Also, your Objective must return doubles.
  2 comentarios
APRA LIPI
APRA LIPI el 26 de Sept. de 2019
Thanks for the answer but how to get the double values from the function?
Here's my objective functon:
function K=Objective(Q)
global SP HCD PC HCS TC Dp
index=["1","2","3"];
Idx=["11","12","13","21","22","23","31","32","33"];
y=optimvar('y',index,'Type','integer');
hd=optimvar('hd',index,'Type','integer');
s=optimvar('s',index,'Type','integer');
hs=optimvar('hs',index,'Type','integer');
x=optimvar('x',Idx,'Type','integer');
SP=[9.39,16.57,14.05];
HCD=[1,1,1];
PC=[1.2,1.2,1];
HCS=[0.12,0.12,0.1];
TC=[2,1,1,2,1,1,2,1,1];
Dp=0.4;
K = (-(Dp*(sum(SP.*y)-sum(HCD.*hd)-sum(PC.*s)-sum(HCS.*hs)-sum(TC.*x))));
end
Matt J
Matt J el 26 de Sept. de 2019
Forget fmincon. Your complete code should look like this
index=["1","2","3"];
Idx=["11","12","13","21","22","23","31","32","33"];
y=optimvar('y',index,'Type','integer');
hd=optimvar('hd',index,'Type','integer');
s=optimvar('s',index,'Type','integer');
hs=optimvar('hs',index,'Type','integer');
x=optimvar('x',Idx,'Type','integer');
SP=[9.39,16.57,14.05];
HCD=[1,1,1];
PC=[1.2,1.2,1];
HCS=[0.12,0.12,0.1];
TC=[2,1,1,2,1,1,2,1,1];
Dp=0.4;
prob=optimproblem;
prob.Objective=(-(Dp*(sum(SP.*y)-sum(HCD.*hd)-sum(PC.*s)-sum(HCS.*hs)-sum(TC.*x))));
solution=solve(prob);
except that you will need additional linear constraints because currently the problem is unbounded.

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Algebra 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!

Translated by