Week 5 - Genetic Algorithm
Aim:
- Write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function.
Governing equation:
f1_x = (sin(5.1*pi*x + 0.5)).⁶;
f1_y = (sin(5.1*pi*y + 0.5)).⁶;
objective: To find out the global maxima with matlab using stalagmite function.
Genetic algorithm:
genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection.
Code:
clc
clear all
close all
%% PROVIDING THE SEARCH SPACE FOR THE FUNCTION
x=linspace(0,0.7,150);
y=linspace(0,0.7,150);
[X,Y]=meshgrid(x,y);
num_cases=500; %Number of itreation for which the function will evaluate the fitness
%% CREATING THE SURFACE PLOT OF STALAGEMITE FUNCTION
for i=1:length(X)
for j=1:length(Y)
input_vector(1)=X(i,j);
input_vector(2)=Y(i,j);
f(i,j)=stalagmite(input_vector); %values of function in given search space
end
end
surfc(X,Y,-f); %generating the surface
xlabel('x value')
ylabel('y value')
shading interp %To remove the lines produced by the mesh grid
function [f] = stalagmite(input_vector)
x = input_vector(1);
y = input_vector(2);
f1_x = (sin(5.1*pi*x + 0.5));
f1_y = (sin(5.1*pi*y + 0.5));
t1 = ((x-0.0667))/(0.64);
f2_x = exp(-4.*log(2)*t1);
t2 = ((y-0.0667))/(0.64);
f2_y = exp(-4.*log(2)*t2);
f = -(f1_x.*f2_x.*f1_y.*f2_y);
end
code Explaination:
providing input space for function using meshgrid.
CREATING THE SURFACE PLOT OF STALAGEMITE FUNCTION
using for loop function.
generating the surface.to line produced by meshgrid.
now using the appropiate formula applying stalagmite function.


