All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
CODE : Function code : function [f] = stalagmite(input_vector)x = input_vector(1);y = input_vector(2); f1_x = (sin((5.1*pi*x)+0.5)).^6; f1_y = (sin((5.1*pi*y)+0.5)).^6; f2_x = exp(((-4*log(2))*(x-0.0667).^2)/0.64); f2_y = exp(((-4*log(2))*(y-0.0667).^2)/0.64); [f] = -(f1_x.*f1_y.*f2_x.*f2_y); end Main code : clear all…
Yogessvaran T
updated on 12 Aug 2022
CODE :
Function code :
function [f] = stalagmite(input_vector)
x = input_vector(1);
y = input_vector(2);
f1_x = (sin((5.1*pi*x)+0.5)).^6;
f1_y = (sin((5.1*pi*y)+0.5)).^6;
f2_x = exp(((-4*log(2))*(x-0.0667).^2)/0.64);
f2_y = exp(((-4*log(2))*(y-0.0667).^2)/0.64);
[f] = -(f1_x.*f1_y.*f2_x.*f2_y);
end
Main code :
clear all
close all
clc
%Defining our search space
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
[xx,yy] = meshgrid(x,y);
num_cases = 80 ;
%calling 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
%Study 1 - Statistical behavior
tic
for i=1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study1_time = toc
figure(1)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title('Unbound inputs')
xlabel('X values')
ylabel('Y values')
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(fopt)
xlabel('Iterations')
ylabel('Function maximum')
%Study 2 - Statistical behavior with upper and lower bounds
tic
for i=1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6]);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study2_time = toc
figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
title('Bounded inputs')
xlabel('X values')
ylabel('Y values')
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(fopt)
xlabel('Iterations')
ylabel('Function maximum')
%Study 3 - Increasing GA iterations
options = optimoptions('ga')
options = optimoptions(options,'populationSize',200)
tic
for i=1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study3_time = toc
figure(3)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
xlabel('X values')
ylabel('Y values')
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(fopt)
xlabel('Iterations')
ylabel('Function maximum')
STEPS :
The code starts with defining x and y as inputs using linspace
A function known as Stalagmite_func is defined as hown in the 2nd stage of codes.
2 for loops are incorporated in the main code so that all the combinations of x and y values is taken in the stalagmite_func
function
In the 1st study GA function runs for 80 iterations. Plots of the stalagmites and maximum values generated in each iteration
is shown.
In the 2nd study GA function is incorporated with lower and upper bounds and runs for 80 iterations. Plots of the stalagmites
and maximum values generated in each iteration is shown.
In the 3rd study GA function is incorporated with lower and upper bounds along with the population size of 200. Plots of the
stalagmites and maximum values generated in each iteration is shown.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 14 challenge
ASSEMBLY OF BUTTERFLY VALVE:- 1.All the parts that are saved in the required folder is opened in the Add components tool box. 2.Now using the Move option and Assembly Constraints option the different parts are joined together with the help of Align,touch,infer/Axis operations. 3. Finally,the assembly of butterfly valve…
18 Feb 2023 09:34 AM IST
Project - Position control of mass spring damper system
To design a closed loop control scheme for a DC motor the following changes need to be done in the model in the previously created model. Speed is the controllable parameter, so we will set the reference speed in step block as 10,20, 40 whichever you want. Subtract the actual speed from the reference speed to generate…
21 Jan 2023 10:29 AM IST
Project - Analysis of a practical automotive wiring circuit
Identify each of the major elements in the above automotive wiring diagram. Ans: Major Elements in the above automotive wiring diagram are - Genarator, Battery, …
14 Dec 2022 03:37 AM IST
Week 6 - Data analysis
-
04 Dec 2022 11:06 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.