Error while running fmincon
이전 댓글 표시
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.
답변 (1개)
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
APRA LIPI
2019년 9월 26일
Matt J
2019년 9월 26일
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.
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!