All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To write a code to optimise stalagmite function and to find the global maxima of the function. THEORY: Genetic algorithm (ga) is a method of solving both constrained and uncontrained optimization problems based on natural selection that mimics biological evolution. ga is the solver like ode45 but…
Shreyas A M
updated on 18 Feb 2020
AIM: To write a code to optimise stalagmite function and to find the global maxima of the function.
THEORY:
Genetic algorithm (ga) is a method of solving both constrained and uncontrained optimization problems based on natural selection that mimics biological evolution.
ga is the solver like ode45 but it optimize the function where as ode45 solve ODE.
In matlab ga is built only to find out the minimum value of the function.
Parameters of genetic algorithm:
Selection:The process that determines which solutions are to be preserved and allowed to reproduce and which ones deserve to die out.
Crossover:It is a convergence operation which is used to pulled out population towards maxima or minima.
Mutation:It is a gentic operator used to maintain genetic diversity from one generation of a genetic alogorithm (example chromosomes) to the next.
ga syntax:
x= ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,intcon,options)
fun=function name
nvars=number of varibles
A and b =linear inequality constraints
lb=lower bounds
ub=upper bounds
nonlcon=non linear constraints
options=optimization options.
Function code used :
function[inputs]=stalagmite(input_vector)
x1=input_vector(1);
y1=input_vector(2);
f1_x=(sin(5.1*pi*x1+0.5))^6;
f1_y=(sin(5.1*pi*y1+0.5))^6;
f2_x=exp(-4*log(2)*(x1-0.0667)^2/0.64);
f2_y=exp(-4*log(2)*(y1-0.0667)^2/0.64);
[inputs]=-(f1_x.*f1_y.*f2_x.*f2_y);
end
Code for global maxima
clear all
close all
clc
%defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
%creating 2d mesh
[xx yy]=meshgrid(x,y);
%stalagmaite function evaualting
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
surfc(xx,yy,f)
xlabel('x value')
ylabel('y value')
shading interp
[inputs, fval]=ga(@stalagmite,2)
To find out minimum value of the function ga
clear all
close all
clc
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
num_cases=50
[xx yy]=meshgrid(x,y);
%stalagmaite function evaualting
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
surf(xx,yy,-f)
shading interp
[inputs, fval]=ga(@stalagmite,2)
xlabel('x value')
ylabel('y value')
title('staglamite function')
tic
% study statistical behaviour
for i=1:num_cases
[inputs, fopt(i)]=ga(@stalagmite, 2);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study1=toc
figure(2)
subplot(3,1,1)
hold on
surfc(x,y,-f)
title('unbounded inputs')
xlabel('x value')
ylabel('y value')
shading interp
hold on
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(3,1,2)
plot(-fopt)
subplot(3,1,3)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
tic;
for i=1:num_cases
[inputs, fopt(i)]=ga(@stalagmite, 2,[],[],[],[],[0;0],[0.07;0.07]);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study2=toc
figure(3)
subplot(2,1,1)
surfc(x,y,-f)
shading interp
title('bounded inputs')
xlabel('x value')
ylabel('y value')
hold on
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
options=optimoptions(@ga)
options=optimoptions(@ga,'populationsize',300)
tic
for i=1:num_cases
[inputs, fopt(i)]=ga(@stalagmite, 2,[],[],[],[],[0;0],[0.07;0.07],[],[],options);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study3time=toc
figure(4)
subplot(2,1,1)
surfc(x,y,-f)
shading interp
title('bounded inputs with increased population size')
xlabel('x value')
ylabel('y value')
hold on
plot3(xopt,yopt,-fopt,'marker','o','markersize',4,'markerfacecolor','r')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
tic;
Staglamite function:
function with ga
Results:
Minimum value of the function is find out and the global maxima for 3studies are showed in the above graphs.
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 4-1D Element Creation Challenge
Mesh the Given component with the Size of 5 Units. Create 1D elements on the following component with given cross-section and DOF a. Rod element:- Translational DOF should be Constrained with RBE2 link Cross-Section: BOX- Dimension a= 12 mm …
01 Apr 2021 11:42 AM IST
Week 10 - Simulating Combustion of Natural Gas.
Aim: Perform a combustion simulation on the combustor model using methane as fuel. Objectives: Part I Perform a combustion simulation on the combustor model and plot the variation of the mass fraction of the different species’ in the simulation using line probes at different locations of the combustor as shown in Fig.…
24 Mar 2021 05:17 PM IST
Week 9 - Parametric study on Gate valve.
Aim: To perform a parametric study on the gate valve simulation by setting the opening from 10 % to 80%. Objective: Obtain the mass flow rates at the outlet for each design point. Calculate the flow coefficient and flow factor for each opening and plot the graph. Discuss the results of the mass flow rate and flow coefficient. …
22 Mar 2021 12:20 PM IST
Week 8 - Simulating Cyclone separator with Discrete Phase Modelling
Aim:- To perform analysis on cyclone separator and calculate the separation efficiency and pressure drop. Objective:- To write a few words about any four empirical models used to calculate the cyclone separator efficiency. To perform an analysis on a given cyclone separator model by varying…
18 Mar 2021 08:43 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.