using for loop in GA in matlab -
using for loop in GA in matlab -
i using ga in matlab solve optimization problem, objective function minimize cost variable v,
function b = cost (v) load ('data.mat'); c1=0; = 1:n j=1:1 c1 = c1 + c(i,j)*v(i,j); end end b=c1;
and constraint const
function [z] = const(v) load ('data1.mat'); z1=1; i=1:n j=1:1 a(i,j) = (1-v(i,j))*t(i,j); z(i,j) = ((a(i,j)+t1)/y(i,j))/(a(i,j)/y(i,j)); end z1 = z1 * z(i,j); end z=[0.7-z1]; zeq=[];
using code ga
lb=zeros(n,1); ub=ones(n,1); intcon = u; options = gaoptimset('plotfcns',{@gaplotbestf,@gaplotmaxconstr},'display','iter'); [v, fval] = ga(@cost,n,[],[],[],[],lb,ub,@const,intcon,options);
where u=[1 2 3 4...n]
i have saved required info in data1.mat file.
i want create objective function , constraint both generalized, otherwise have write r
,a
, c
value n
number of times.
problem when run it, gives message
%error using ga (line 342) %too many output arguments. %caused by: %failure in initial user-supplied nonlinear constraint function evaluation.
you need utilize varargout
variable output argument in matlab. replace code's output argument i.e. have defined ga
function. instead of array, should varargout{}
. there illustration on mathworks site how this.
possibly alter input , output arguments varargin , varargout respectively. seems need throughout.
hope helps!
matlab
Comments
Post a Comment