Page 24 - Algorithm Collections for Digital Signal Processing Applications using MATLAB
P. 24

12                                                          Chapter 1

            geneticgv.m

           clear all, close all
           pop=0:0.001:9;
           pos=round(rand(1,10)*9000)+1;
           pop1=pop(pos);
           BEST=[];
           for iter=1:1:100
               col1=[];
               col2=[];
               for do=1:1:10
               r1=round(rand(1)*9)+1;
               r2=round(rand(1)*9)+1 ;
               r3=rand;
               v1=r3*pop1(r1)+(1-r3)*pop1(r2);
               v2=r3*pop1(r2)+(1-r3)*pop1(r1);
               col1=[col1 v1 v2];
               end
               sect=fcn(col1)+abs(min(fcn(col1)));
               sect=sect/sum(sect);
               [u,v]=min(sect);
               c=cumsum(sect);
               for i=1:1:10
               r=rand;
               c1=c-r;
               [p,q]=find(c1>=0);
               if(length(q)~=0)
               col2=[col2 col1(q(1))];
               else
               col2=[col2 col1(v)];
               end
               end
           pop1=col2;
               s=fcn(pop);
               plot(pop,s)
               [u,v]=max(fcn(pop1));
               BEST=[BEST;pop1(v(1)) fcn(pop1(v(1)))];
               hold on
               plot(pop1,fcn(pop1),'r.');
               M(iter)=getframe;
               pause(0.3)
               hold off
               [iter pop1(v(1)) fcn(pop1(v(1)))]
           end
   19   20   21   22   23   24   25   26   27   28   29