%stalagmite function
function[f]=stalagmite(input_vector)
x=input_vector(1);
y=input_vector(2);
t1=(sin((5.1*pi*x)+0.5))^6;
t2=(sin((5.1*pi*y)+0.5))^6;
t3=exp(-4*log(2)*((x-0.0667)^2)/0.64);
t4=exp(-4*log(2)*((y-0.0667)^2)/0.64);
f=-(t1*t2*t3*t4);
end
clear all
close all
clc
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
n=50;
%Creating a 2D mesh
[xx yy]=meshgrid(x,y);
%Evaluating stalagmite 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)=stalagmite(input_vector);
end
end
%Study1 : Statistical behaviour
tic
for i=1:n
[inputs,fopt(i)]=ga(@stalagmite,2);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study1_time=toc
figure(1)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
%Labelling axis
xlabel('X-axis')
ylabel('Y-axis')
title('statistical behaviour with unbound inputs')
plot3(xopt,yopt,-fopt,'marker','o')
subplot(2,1,2)
plot(-fopt)
xlabel('Number of iterations')
ylabel('Function maximum')
%study 2: Satistical behaviour with upper and lower bounds
tic
for i=1:n
[inputs,fopt(i)]=ga(@stalagmite,2,[ ],[ ],[ ],[ ],[0;0],[1;1]);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study2_time=toc
figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
xlabel('X-axis')
ylabel('Y-axis')
title('statistical behaviour with upper and lower bounds')
plot3(xopt,yopt,-fopt,'marker','o')
subplot(2,1,2)
plot(-fopt)
xlabel('Number of iterations')
ylabel('Function maximum')
%study 3: Statistical behaviour with increasing iterations of GA
options=optimoptions('ga');
options=optimoptions(options,'PopulationSize',300);
tic
for i=1:n
[inputs,fopt(i)]=ga(@stalagmite,2,[ ],[ ],[ ],[ ],[0;0],[1;1],[ ],[ ],options);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study3_time=toc
figure(3)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
xlabel('X-axis')
ylabel('Y-axis')
title('statistical behaviour with increasing iterations')
plot3(xopt,yopt,-fopt,'marker','o')
subplot(2,1,2)
plot(-fopt)
xlabel('Number of iterations')
ylabel('Function maximum')