STALAGMITE FUNCTION
AIM:
To write code in MATLAB to optimize the stalagmite function and find the global maxima of the function
STALAGMITE:
A stalagmite mathematical model is used to develop the local maxima or minima. Here to determine the optimum solution of the maxima of function we are using Generic algorithm technique.
GENERIC ALGORITHM(GAs):
GAs is an optimization technique used to solve non linear problems. It is used to concept od evolutionary biology(Darwin’s Theory of Evolution ) to find the global minima for optimization problem
STALAGMITE FUNCTION CODE
function [f] = stalagmite_fun(input_vector)
f1x = (sin((5.1*pi).*input_vector(1)+0.5)).^6;
f1y = (sin((5.1*pi).*input_vector(2)+0.5)).^6;
f2x = exp((((input_vector(1)-.0667).^2)/.64).*(-4*log(2)));
f2y = exp((((input_vector(2)-.0667).^2)/.64).*(-4*log(2)));
f1 = f1x*f1y*f2x*f2y;
f = -f1;
end
MAIN CODE:
clear all
close all
clc
%input values
num_cases = 50;
x = linspace(0,.6,150);
y = linspace(0,0.6,150);
[xx yy] = meshgrid(x,y)
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_fun(input_vector);
end
end
%study-1 %plotting sstalagmite function
for i = 1:num_cases
[inputs,fopt(i)] = ga(@stalagmite_fun,2);
xxopt(i) = inputs(1);
yyopt(i) = inputs(2);
end
figure(1)
subplot(2,1,1);
hold on
surf(x,y,-f)
shading interp
plot3(xxopt,yyopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(-fopt)
xlabel('iteration')
ylabel('function minimum')
%study-2 %plotting sstalagmite function
for i = 1:num_cases
[inputs , fopt(i)] = ga(@stalagmite_fun,2,[],[],[],[],[0,0],[0.6,0.6]);
xxopt(i) = inputs(1);
yyopt(i) = inputs(2);
end
figure(2)
subplot(2,1,1);
hold on
surf(x,y,-f)
shading interp
plot3(xxopt,yyopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(-fopt)
xlabel('iteration')
ylabel('function minimum')
%study-2 plotting sstalagmite function
options = optimoptions('ga')
options = optimoptions(options,'populationsize',500)
for i = 1:num_cases
[inputs , fopt(i)] = ga(@stalagmite_fun,2,[],[],[],[],[0,0],[0.6,0.6],[],[],options);
xxopt(i) = inputs(1);
yyopt(i) = inputs(2);
end
figure(3)
subplot(2,1,1);
hold on
surf(x,y,-f)
shading interp
plot3(xxopt,yyopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
title('unbounded inputs')
subplot(2,1,2)
plot(-fopt)
xlabel('iteration')
ylabel('function minimum')
CODE EXPLANATION:
Firstly creating an random x and y 2D array using meshgrid function. The loop is used to assign input values to 2D array. A function is used to solve the stalagmite equation then we adding that function into GA solvers and we getting sn output .
The next step we taking different cases and (-) sign is used to invert the graph for getting global maxima point in first case boundaries are not defined and the pot were made. The boundaries in next case we taking the values more accurate. The population is increased the subsequent cases and plotting is done. The global maxima found in the last case the x& y values for which the function has maximum value is also displayed the iteration were decreased to such a value the didn’t vary and the program consumed min time executed.
RESULT:
The global maxima of stalagmite function is optimized using generic algorithm in MATLAB.