Week 4.1 - Genetic Algorithm
CODE 1:
clear all
close all
clc
% x definig the search space
x= linspace(0,0.6,150);
y= linspace(0,0.6,150);
% x creating a 2D dimensional mesh
[xx yy]=meshgrid(x,y);
% evalting the stalagmit funtion
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)=stalagmite(input_vector);
end
end
surfc(xx,yy,-f);
shading interp
for i = 1:50
[x fval_1(i)]= ga(@stalagmite,2);
end
for i = 1:50
[x fval(i)]= ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6]);
end
options=optimoptions('ga','PopulationSize',250)
for i = 1:50
[x fval_2(i)]= ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
end
CODE 2:
function [f]=stalagmite(input_vector)
x=input_vector(1);
y=input_vector(2);
% the equation of the stalagmite function depends on 2 variables x,y
% the out come formula
a=(sin(5.1*pi*x+0.5))^6;
b=(sin(5.1*pi*y+0.5))^6;
c=exp(-4*log(2)*((x-0.0667)^2)/0.69);
d=exp(-4*log(2)*((y-0.0667)^2)/0.69);
f=-1*(a*b*c*d );
end
FIGURE: stalagmite

EXPLINATION:
AIM: Here we are discussion abour the genetic alogrithm like 'ga' code
THEROY:The genetic alogrithm function works on the finding the different types of the actions and the these are the can be used to find out the different point iof the maxim and minium irrtations and these are the ga function
CODE1: In the code we can see how the ga function works for the different functins like the upper boundaries and the lower boundaries and the maxium and the minium points
CODE2:In this code we have written the function of the stalagmite so that we can get the function
FIGURE:The figure which we are getting is how the stalagmite function look likes actually
THE END