Project

Genetic algorithm

clear all
close all
clc

%dividing x,y into 150 parts between the range 0 to 0.6
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
cases=50; %total cases =50
[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(input_vector);
    end
end


options=gaoptimset(@ga);%intializing options setting for GA
options=gaoptimset(options,\'PopulationSize\',200);%setting population size to 200

tic
for i= 1:cases
    [inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    %(function,no_of_variables,linear inequalities,linear equalities,bounds,nonlinear constraint func,interger indices,opts)
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end

time=toc
figure(1)
subplot(2,1,1)
hold on
surfc(x,y,f)%plotting the surfaces
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\')%ploting min values for each case with marker o
title(\'Bounded inputs\')
subplot(2,1,2)
plot(fopt) 
xlabel(\'iterations\');
ylabel(\'Min. func\');
%since GA finds only minimum value, we did fuction=-(function) to inverse
%the plot. but now the maximum value is around 0.99995 we assume.
function [q]=stalagmite(qw)
f1=(sin(5.1*pi*qw(1)+0.5)).^6;
f2=(sin(5.1*pi*qw(2)+0.5)).^6;
f3=exp(-4*log(2)*(qw(1)-0.0667)^2/0.64);
f4=exp(-4*log(2)*(qw(2)-0.0667)^2/0.64);
q=f1*f2*f3*f4;
q=-q;
end

the answer is 0.99995.

\"\"

the iterations are more variying because of more accuracy of the value (0.0000)

if it was 0.999, all values are the same only

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.