Hi , I amd new using matlab and I would want to know how can I plot every generation of child ( xh) and see how has improve each generation in each iteration of jj. Total of generations are 200.
Code is below.
clear all
close all
clc
f = @(x,y) x*exp(-x^2 -y^2);
Ge = 200;
N = 50;
D = 2;
xl = [-2 ; -2];
xu = [2 ; 2];
aptitud = zeros(1,N);
x = zeros(2,N);
for i=1:N
x(:,i) = xl+(xu - xl).*rand(2,1);
end
for jj=1:Ge
for i=1:N
fx = f(x(1,i),x(2,i));
if fx >= 0
aptitud(i) = 1/(1+fx);
else
aptitud(i) = 1+abs(fx);
end
end
xh = zeros(2,N);
for k=1:2:N
p1 = seleccion(aptitud);
p2 = p1;
while p2 == p1
p2 = seleccion(aptitud);
end
[h1,h2] = cruza(x(:,p1),x(:,p2));
xh(:,k) = h1;
xh(:,k+1) = h2;
end
pm = 0.3;
for i=1:N
for j=1:D
if rand > pm
else
xh(j,i) = xl(j) + (xu(j) - xl(j))*rand();
end
end
end
x = xh;
end