Error while running fmincon
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Matt J
le 25 Sep 2019
Modifié(e) : Matt J
le 25 Sep 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 commentaires
Matt J
le 26 Sep 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.
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!