Challenge

Week 4.1 - Genetic Algorithm

close all
clear all
clc

% defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);

% creating a 2D mesh
[xx,yy]=meshgrid(x,y);

% evaluating the stalgamite function
for i=1:length(xx)
for j=1:length(yy)
input_vector(1)=xx(i,j);
input_vector(2)=yy(i,j);
f(i,j)=stalagamite(input_vector);
end
end
surf(xx,yy,f)
shading interp
hold on
%study 1
%for i=1:20
% [xy,z]=ga(@stalagamite,2);
% plot3(xy(1),xy(2),z,'o')
%end
% study 2
%subplot(2,1,1)
%surf(xx,yy,f)
%shading interp
%hold on

%for i=1:20
% [xy,z]=ga(@stalagamite,2,[],[],[],[],[0;0],[1;1]);
% plot3(xy(1),xy(2),z,'o')
%end
%subplot(2,1,2)
%plot(z)
% study 3
options=optimoptions('ga');

options=optimoptions(options,'populationsize',150);
figure(3)
subplot(2,1,1)
surf(xx,yy,f)
shading interp
hold on
for i=1:20
[xy,z(i)]=ga(@stalagamite,2,[],[],[],[],[0;0],[1;1],[],[],options);
plot3(xy(1),xy(2),z(i),'o')
end
subplot(2,1,2)
plot(z)

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.