All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM : To create a code in MATLAB to optimise the stalagmite function and find the Global maxima of the function. THEORY : Genetic algorithms are a type of gradient free optimization algorithm. These algorithms are based on the ideas of biology and evolution. This algorithm is a random-based classical evolutionary…
Ashutosh Trehan
updated on 15 Jun 2020
AIM :
To create a code in MATLAB to optimise the stalagmite function and find the Global maxima of the function.
THEORY :
Concept & working of Genetic Algorithm(GA) :
Genetic algorithm uses three main types of rules at each step to create the next generation from the current population:
Syntax of Ga used in MATLAB
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
GOVERNING EQUATIONS :
Equations used in stalagmite function are as follows -
OBJECTIVES OF THE PROJECT:
FUNCTION CODE :
function [f] = stalagmite_Func(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*f2_x*f1_y*f2_y);
end
MAIN CODE :
%% PROGRAM FOR STALAGMITE MATHEMATICAL MODEL USING GA
clear all
close all
clc
% Preparing or Defining the Search space
x = linspace(0,0.6,150) ; % Assigning the range for x co-ordinates
y = linspace(0,0.6,150) ; % Assigning the range for y co-ordinates
% Creating a Array or 2D MESH for search space
[X , Y] = meshgrid(x,y) ; % Giving inputs x and y to form 2D Mesh
% No. of Iterations
num_case = 100;
% Evaluating the Stalagmite function
for i = 1:length(X)
for j = 1:length(Y)
Input_vector(1) = X(i,j); % Input vector for x
Input_vector(2) = Y(i,j); % Input vector for y
f(i,j) = stalagmite_Func(Input_vector); % Calling the stalagmite Function
end
end
surfc(X,Y,f)
xlabel('x values')
ylabel('y values')
shading interp % Using shading command to removing the grid lines
[inputs , fval] = ga(@stalagmite_Func , 2)
% STUDY 1 Statistical Behaviour
tic % Using tic to start stopwatch timer
for i = 1 : num_case
[inputs, f_opt(i)] = ga(@stalagmite_Func,2); % Using ga for stalagmite function
x_opt(i) = inputs(1); % Storing the x values
y_opt(i) = inputs(2); % Storing the y values
end
study1_time = toc
figure(1)
subplot(2,1,1) % To plot multiple plots using subplot
hold on
surfc(x,y,-f) % Plotting surface for x vs y with function
shading interp
plot3(x_opt,y_opt,-f_opt,'marker','o','markersize',5,'markerfacecolor','r')
title('UNBOUNDED INPUT')
subplot(2,1,2)
plot(-f_opt)
xlabel('No.of Iterations')
ylabel('Maximum Function Value')
% STUDY 2 Statistical Behaviour with Upper and Lower Bounds
tic
for i = 1 : num_case
[inputs, f_opt(i)] = ga(@stalagmite_Func,2,[],[],[],[],[0;0],[1;1]); % Using ga commmand & giving lower and upper bounds
x_opt(i) = inputs(1); % Storing the x values
y_opt(i) = inputs(2); % Storing the y values
end
study2_time = toc % Using toc to read the elapsed time from timer
figure(2)
subplot(2,1,1) % To plot multiple plots using subplot
hold on
surfc(x,y,-f) % Plotting surface for x vs y with function
shading interp
plot3(x_opt,y_opt,-f_opt,'marker','o','markersize',5,'markerfacecolor','r')
title('BOUNDED INPUTS')
subplot(2,1,2)
plot(-f_opt)
xlabel('No.of Iterations')
ylabel('Maximum Function Value')
% STUDY 3 Statistical Behaviour by Increasing GA Iterations
options = optimoptions('ga')
options = optimoptions(options,'PopulationSize',350) % Giving the population size to 350 for ga
tic % Using tic to start stopwatch timer
for i = 1 : num_case
[inputs, f_opt(i)] = ga(@stalagmite_Func,2,[],[],[],[],[0;0],[1;1],[],[],options); % Using ga commmand & giving lower and upper bounds
x_opt(i) = inputs(1); % Storing the x values
y_opt(i) = inputs(2); % Storing the y values
end
study3_time = toc % Using toc to read the elapsed time from timer
figure(3)
subplot(2,1,1) % To plot multiple plots using subplot
hold on
surfc(x,y,-f) % Plotting surface for x vs y with function
shading interp
plot3(x_opt,y_opt,-f_opt,'marker','o','markersize',5,'markerfacecolor','r')
title('BOUNDED INPUTS with Modified Population Size ')
subplot(2,1,2) % To plot multiple plots using subplot
plot(-f_opt) % Plot for the optimum function
xlabel('No.of Iterations')
ylabel('Maximum Function Value')
OUTPUTS :
The above output plot gives the results for unbounded input in which we get the x_optimum vs y_optimum over optimum function over the surface showing randomly populated results without the restrictions which is not appropriate. The sub plot output shows the no of iterations on x axis vs the maximum value for the function on y axis in which iterations starts from 1 to 100 and function value starts from 0.6-0.7 respectively.
The above output plot gives the results for Bounded input in which we get the x_optimum vs y_optimum over optimum function over the surface showing results with the restrictions that is the upper and the lower bounds which is more accurate & better than the study 1 output to reach global maxima.The sub plot output shows the no of iterations on x axis vs the maximum value for the function on y axis in which iterations starts from 1 to 100 and function value starts in between 0.5-0.6 respectively.
The above output plot gives the results for Bounded input with the modified population for ga in which we get the x_optimum vs y_optimum over optimum function over the surface showing results with the limitations that is the upper and the lower bounds which is more accurate & best than the study 2 output for global maxima.The sub plot output shows the no of iterations on x axis vs the maximum value for the function on y axis in which iterations starts from 1 to 100. Here, we get the exact global maxima on the peak after using the population size as 350 respectively.
STEPWISE EXPLANATION OF THE CODE :
[inputs, f_opt(i)] = ga(@stalagmite_Func,2,[],[],[],[],[0;0],[1;1])
i.e. for exp*(-4*log()… ) which is wrong.
CONCLUSION :
Optimization is best suited to find the extreme stage either to maximize or minimize function of any real world case. Here, after performing 3 case study we finally get the global maxima in study 3 after iterating the population size respectively. Also, we had briefly undertsood the stalagmite function to optimize and the concept of GA easily by using MATLAB.
REFERENCES -
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...
MBD Simulation on IC Engine Valve Train
AIM : To create models, assembly & perform Motion analysis for the IC engine valve train . OBJECTIVE : To obtain the results for Valve Lift. Calculate and display the plots for contact force between Cam and Push Rod, Pushrod and Rocker Arm, Rocker Arm and Valve. INTRODUCTION : In IC engines, valve…
08 Dec 2020 12:46 PM IST
STATIC ANALYSIS FOR A PLATE WITH HOLES
AIM : To perform the Static Analysis on two different models of a plate with the holes and the comparison of results among the two models. OBJECTIVE : Prepare a static analysis and get the output for stress, strain and displacement for two models of plate with holes. Compare the final results of static analysis for the…
08 Dec 2020 12:46 PM IST
EV battery module Benefits and Specifications
AIM : To study the benefits of using Battery modules and specifications of an individual module specified for an battery pack. INTRODUCTION : A battery is a device that converts chemical energy into electrical energy and vice versa. The composition of an EV battery might vary slightly depending on the types of electric…
08 Dec 2020 12:45 PM IST
Frequency Analysis of a rotating shaft
AIM : To perform frequency analysis for a rotating shaft with disc in solidworks. OBJECTIVE : Conduct a frequency analysis on the rotating shaft with disc. Determine the 5 different mode shapes and display its resonant frequencies. INTRODUCTION : The goal of modal analysis in a model is to determine the natural mode…
08 Dec 2020 12:44 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.