n=10;
lambda=50;
mu=5;
Ngen=200;
sigma=0.01;
//
function y=sphere(x)
    y=sum(x.*x);
endfunction
//
Ap=2*rand(mu,n+1)-ones(mu,n+1)// initialisation
Ae=zeros(lambda,n+1)
BestJ=[]
BestX=[]
//
for i=1:Ngen
//    
  X=1/mu*sum(Ap(:,1:n),'r')  // croisement
  val=sphere(X);ps=0;//    
  for i=1:lambda
     Ae(i,1:n)=X+sigma*rand(1,n,'normal') // mutation
     Ae(i,n+1)=sphere(Ae(i,1:n))   // evaluation
     if (Ae(i,n+1)<val)then ps=ps+1;end
  end
  ps=ps/lambda;
  sigma=sigma*exp(1/3*(ps-1/5)/(1-1/5));
  [a,b]=gsort(-Ae(:,n+1))
  Ae=Ae(b,:)
  Ap=Ae(1:mu,:)  // selection
  BestJ=[BestJ,Ae(1,n+1)]
  BestX=[BestX;Ae(1,1:n)]
end 
figure(1)
clf() 
plot(1:Ngen,BestJ)
figure(2)
clf()
for j=1:n
 plot2d(1:Ngen,BestX(:,j),j)
end


  

