Project

Optimizing Stalagmite Function using Genetic Algorithm in MATLAB

1)Main Program

clear all
close all
clc

x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
num_cases=100;
f=get_stalagmite1(x,y);

options=optimoptions(\'ga\')
options=optimoptions(options,\'PopulationSize\',250);

for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite_func2,2,[],[],[],[],[0;0],[0.6;0.6],[],options)
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end
%global maxima 
globalmaxima=abs(fopt(i))

%plotting figure

figure(1)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\'bounded inputs\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')

2) function to call stalagmite function

function [f]=get_stalagmite1(x,y)

[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_func2(input_vector);
        
    end
   
end


end

3)Function to calculate the value of function

function [ft]=stalagmite_func2(input_vector)

f1=(sin(5.1*pi*input_vector(1)+0.5)).^6;

f2=(sin(5.1*pi*input_vector(2)+0.5)).^6;

f3=exp(-4*log(2)*((input_vector(1)-0.0667).^2/0.64));

f4=exp(-4*log(2)*((input_vector(2)-0.0667).^2/0.64));

ft=-(f1*f2*f3*f4);
end

4) Images of the plot after 100 iterations:

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.