Challenge

Week 4.1 - Genetic Algorithm

PROGRAM FOR STALAGMITE MODEL :
close all
clear all
clc
num_cases=150;
x=linspace(0,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(input_vector);
end
end
tic
for i=1:num_cases
[inputs,fopt(i)]= ga(@stalagmite,2);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
fopt=-fopt;
time_study1=toc
%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('Unbound inputs')
%figure(2)
subplot(2,1,2)
plot(fopt)
xlabel('Iteration')
ylabel('Function minimum')
%study2
tic
for i=1:num_cases
[inputs2,fopt2(i)]= ga(@stalagmite,2,[],[],[],[],[0,0],[1,1]);
xopt2(i)=inputs2(1);
yopt2(i)=inputs2(2);
end
fopt2=-fopt2;
time_study2=toc
figure(2)
subplot(2,1,1)
hold on
surfc(x,y,-f)
shading interp
plot3(xopt2,yopt2,fopt2,'marker','o','markersize',5,'markerfacecolor','r')
title('Bounded inputs')
%figure(2)
subplot(2,1,2)
plot(fopt2)
xlabel('Iteration')
ylabel('Function minimum')
%Case_study 3: MAximising the population size to optimise the result
options= optimoptions ('ga');
options=optimoptions(options,'PopulationSize',350);
tic
for i=1:num_cases
[inputs3, fopt3(i)]=ga(@stalagmite,2,[],[],[],[],[0,0],[1,1],[],[],options);
xopt3(i)=inputs3(1);
yopt3(i)=inputs3(2);
end
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,-f)
shading interp
plot3(xopt3,yopt3,-fopt3,'marker','o','markersize',5,'markerfacecolor','r')
title('Bounded inputs with optioptims function')
subplot(2,1,2)
plot(-fopt3)
xlabel('Iteration')
ylabel('Function minimum')
time_study3=toc
rng('default');
-------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION FOR STALAGMITE :
function[f]= stalagmite(input_vector)
fx=(sin(5.1*pi*input_vector(1)+0.5))^6;
fy=(sin(5.1*pi*input_vector(2)+0.5))^6;
fxx=exp((-4*log(2)*(((input_vector(1)-0.0667)^2)/0.64)));
fyy=exp(-4*log(2)*(((input_vector(2)-0.0667)^2)/0.64));
f=-(fx*fy*fxx*fyy);
end
-------------------------------------------------------------------------------------------------------------------------------------------
CHALLENGE REPORT :
I) First start the pgm. with clear all, close all, clc .
ii) Second the x and y co-ordinates and also give the num_cases.
iii) Next pgm. for loop with start and end.
iv) Next plot the figure (1) and do the for loop for the figure (1) pgm..
v) Like the figure (1) plot figure(2) & (3) , and do the for loop for thet .
vi) Do a function for plotting the values and save the function in the same file where the pgm. is located, so that it will be very easy to do be identified by the pgm..
vii) Now save the file and run the pgm..
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.