# index out of bounds because size(yout)=[0,0] / optimization with fmincon

1 view (last 30 days)
Sébastien on 7 Nov 2013
Commented: Sébastien on 7 Nov 2013
Hi I'm trying to execute an optimization program but i keep getting this error:
"??? Attempted to access yout(1,1); index out of bounds because size(yout)=[0,0]"
And
" Error in ==> fmincon at 540
initVals.f = feval(funfcn{3},X,varargin{:}); "
I do not understand what does it mean. Is someone ready to help me?
My program is:
function [Apv, Awt, Ah] = minimum_cost
hybrid_simulator_multi
design0 = [10 10 200];
ndcdc=0.95;
nacdc=0.95;
ndis=1;
nch=0.85;
ninv=0.95;
nwr=0.98;
Vwind=data_2010(:,2);
Ir=data_2010(:,1);
Ta=data_2010(:,3);
yout=[];
designold=[];
options = optimset('fmincon');
options=optimset(options,'Display','iter','TolX',0.001,'TolFun',0.001);
options=optimset(options,'Algorithm','sqp');
design = fmincon(@trackmmobj,design0,[],[],[],[],[6 6 150],[15 12 300],@trackmmcon,options);
Apv = design(1); Awt = design(2); Ah = design(3);
function F = trackmmobj(design)
F(1) = yout(1,1);
end
function [c,ceq] = trackmmcon(design)
c =yout(end,3)-5;
ceq=[];
end
end

Vivek Selvam on 7 Nov 2013
In your code, you have initialized yout to an empty matrix ( yout = []). Then in function trackmmobj, you are trying to access the first element of yout. This throws an error - index out of bounds.
Sébastien on 7 Nov 2013
Yes, thank you! I forgot :
opt = simset('SrcWorkspace','Current');
[tout,xout,yout] = sim('hybrid_simulator_multi',[],opt);
This code provides "yout" with simulation in Simulink.
But, there is with fmincon:
Error in ==> fmincon at 540
initVals.f = feval(funfcn{3},X,varargin{:});
Where is my mistake?
Thank you very much.