fmincon error, please help me!

fzstage2 = @(fkj, h2k, h2l) zstage2([fkj, h2k, h2l], demandrateSubregionBothDCs(1,j),...
distances(DCindexk, j), distances(DCindexl, j), spatialpointdensity(j),...
k, numberofstops(j), s2, ts, vmax2, cd, cr, dcs, ci, cif, cs);
fzstage2con = @(fkj, h2k, h2l) zstage2con([fkj, h2k, h2l], demandrateSubregionBothDCs(1,j),...
distances(DCindexk, j), distances(DCindexl, j), spatialpointdensity(j),...
k, numberofstops(j), s2, ts, vmax2);
decVar0=[0.5 1 1];
lb=[0,0,0];
ub=[1, 1000, 1000];
options=optimset('largescale','off','display','iter');
[decVaropt,fval,exitflag,output] = fmincon(fzstage2,decVar0,[],[],[],[],lb,ub,fzstage2con,options);
Err Msg:
Error using
@(fkj,h2k,h2l)zstage2([fkj,h2k,h2l],demandrateSubregionBothDCs(1,j),distances(DCindexk,j),distances(DCindexl,j),spatialpointdensity(j),k,numberofstops(j),s2,ts,vmax2,cd,cr,dcs,ci,cif,cs)
Not enough input arguments.
Error in fmincon (line 601)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation.
FMINCON cannot continue.
function [ zstage2con ceq ] = zstage2con( DECVAR, DtotStage2j, rkj, rlj, SPDj, k, nsj, s2, ts, vmax2)
fkj = DECVAR(1);
h2k = DECVAR(2);
h2l = DECVAR(3);
...
function zstage2 = zstage2( DECVAR, DtotStage2j, rkj, rlj, SPDj, k, nsj, s2, ts, vmax2, cd, cr, dcs, ci2, cif, cs)
fkj = DECVAR(1);
h2k = DECVAR(2);
h2l = DECVAR(3);
...
help! T_T

Respuestas (1)

Alan Weiss
Alan Weiss el 17 de Jul. de 2014

0 votos

If I understand you, then this is a syntax error. fmincon expects that the objective function is a function of one variable. This variable can be a matrix or vector. So if you have variables fkj, h2k, and h21, you should write your objective function as
function y = zstage(x)
fkj = x(1:21); % assumes fkj is a 21-element vector
h2k = x(22:40); % h2k is a 19-element vector
h21 = x(41); % h21 is a scalar
...
Or, if you want to include some parameters in your objective function, do it as described here.
If I misunderstood what you were asking, feel free to ask again.
Alan Weiss
MATLAB mathematical toolbox documentation

Etiquetas

Preguntada:

el 17 de Jul. de 2014

Respondida:

el 17 de Jul. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by