clear all
close all
clc
% x = input_vector(1);
% y = input_vector(2);
%
% 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.64);
% d = exp(-4*log(2)*((y-0.0667)^2)/0.64);
%
% f= -(A*B*C*d);
%defining the search space
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
n = 50
%2d mesh
[xx,yy] = meshgrid(x,y);
%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
%studying the statistical behaviour - 1
tic
for i = 1:n
[inputs, foptimum(i)] = ga(@stalagmite,2);
xoptimum(i) = inputs(1);
yoptimum(i) = inputs(2);
end
study1_time = toc
figure(1)
subplot(2,1,1)
hold on
surf(xx,yy,-f)
shading interp
xlabel = ('X_axis')
ylabel = ('Y_axis')
title('studying the statistical behaviour unbound output')
plot3(xoptimum,yoptimum,-foptimum,'o', 'MarkerSize',2,'MarkerFaceColor','r')
subplot(2,1,2)
plot(-foptimum)
xlabel('no of iterations')
ylabel ('function maxima')
%studying statical behaviour with upper and lower bounds
for i = 1:num_case
[input,foptimum(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
xoptimum(i) = inputs(1);
yoptimum(i) = inputs(2);
end
study2_time = toc
figure(2)
subplot(2,1,1)
hold on
surf(x,y,f)
shading interp
xlabel = ('X_axis')
ylabel = ('Y_axis')
title('bounded output')
plot3(xoptimum,yoptimum,foptimum,'o', 'MarkerSize',2,'MarkerFaceColor','r')
subplot(2,1,2)
plot(foptimum)
xlabel('iteration')
ylabel ('function minima')
%increasing the ga iterations study-4
tic
options = optimoptions('ga');
options = optimoptions(options,'populationsize',270);
for i = 1:num_case
[input,foptimum(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
xoptimum(i) = inputs(1);
yoptimum(i) = inputs(2);
end
study3_time = toc
figure(3)
subplot(2,1,1)
hold on
surf(x,y,f)
shading interp
xlabel = ('X_axis')
ylabel = ('Y_axis')
title('bounded output')
plot3(xoptimum,yoptimum,foptimum,'o', 'MarkerSize',2,'MarkerFaceColor','r')
subplot(2,1,2)
plot(foptimum)
xlabel('iteration')
ylabel ('function minima')
The 'x' and 'y' array is defined using 'linspace' command to create value at 150 intervals.
2D mesh is created for x and y using meshgrid and numbwer of iteration is given by n = 50.
The input vector 'xx' and 'yy' are defined and stalagmite functionfor these input vector is defined.
To know the time that is taken to solve the loop for 50 iteraqtions 'tic' 'toc' command is used before the loop command.
Then the function created in the loop is plooted using the 'surfc' command.
Due to some error the plot number 2,3 is not plotted.