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 in MATLAB to optimise the stalagmite function and find the global maxima of the function by using matlab. EXPLANATION OF GENETIC ALGORITHM:A Genetic Algorithm was proposed by charles darwin.the genetic algorithm inspired by the process of natural selection that belongs to the larger class of evolutionary…
Mohmmed Riyaz
updated on 07 Mar 2022
AIM: To Write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function by using matlab.
EXPLANATION OF GENETIC ALGORITHM:A Genetic Algorithm was proposed by charles darwin.the genetic algorithm inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms.it is used for the high quality solution of optimization.this methods are five phases in genetic algorithm.
1.initial population-the process begins with the set of individuals which is called a population.an individual is characterized by a parameters known as genes. genes are joined into a string to form a chromosome.the set of individual is represented by using a string which the binary values are used as 0's and 1's.we encode the genes in chromosome.
2.fitness function-it determines how fit an individual.it gives a fitness score to each individual.the probability that an individual will be selected for reproduction is based on its fitness score.
3.selection-the idea of selection phase is to select the fitness individuals and let them pass their genes to next generation.two pairs of individuals(i.e.parents)are based on fitness scores.individuals with high fitness have more chance to be selected for reproduction.
4.cross over-cross over is the most significant phase in a genetic algorithm.for each pair of parents to be mated,a cross point is chosen at random within the genes.offsprings are created by exchanging the genes of parents among themselves until the cross over point is reached.
5.mutation-Certain newspring is formed,some of the genes can be subjected to a mutation with a low random probability. this implies that some of the bits in the bit string can be flipped.
syntax of genetic algorithm:
For (ex: x=ga(func,nvars)) to find the local unconstrained minimum,x, to the objective function,fun.nvars is the dimension (number of design variables) of function.
CODES AND EXPLANATION OF CODES:
1.The function should be declared with the name stalagmite.
2.The input variables of x and y are assigned.
3.The formula f(x,y)=f1x,f2x,f1y,f2y. of each individual polynomial is taken as ax,ay,bx,by.the below polynomial function is used
f(x,y)=f1x,f2x,f1y,f2y
f1x=[sin(5.1πx+0.5)]^6
f1y=[sin(5.1πy+0.5)]^6
f2x=exp(-4ln(2)((x-0.0667)²/0.64)))
f2y=exp(-4ln(2)((y-0.0667)²/0.64)))
4.Finally the -ive sign is used to optimize stability for the GA function(taking the minimum value)
5.After complete the function the main program has bee coded ,the linspace command is used which to difine the search space which should be inital value is 0 and the final value is 0.6.it is divided in to 150parts.
6.The points red is used for node points.
7.Meshgrid command is used for generating the 2d dimension.
8.For loop is used for repeating the sets.
9.surfc command is used to creating the surface of the plot and it can be filled.
10.The codes should be written by 3study plotted.
11.Three statistics is increasing the number of iterations that gives the output.
functions os stalagmite:
function [f]=stalagmite(input_vector)
x=input_vector(1);
y=input_vector(2);
ax=(sin(5.1*pi*x+0.5))^6;
ay=(sin(5.1*pi*y+0.5))^6;
bx= exp(-4*log(2)*(((x-0.0667)^2)/0.64));
by=exp(-4*log(2)*(((y-0.0667)^2)/0.64));
f=-(ax*bx*ay*by);
end
main program:The stalagmite function should be coded above.
clear all
close all
clc
%defining the initial inputs
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
num_cases=50;
%create a 2dimensional array
[xx,yy]=meshgrid(x,y);
%evaluate the 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
end
tic
for i=1:num_cases
[inputs,fopt(i)]=ga(@stalagmite,2);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_time=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('unbounded inputs')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
tic
%study 2-statistical behaviour
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(x, y, -f)
shading interp
plot3(xopt,yopt,-fopt,'marker','o','MarkerSize',5,'MarkerFaceColor','r')
title('bounded inputs')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
%study 3-statistical behaviour
options=optimoptions('ga')
options=optimoptions(options,'PopulationSize',150);
tic
for i = 1:num_cases
[inputs, fopt(i)] = ga (@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study3_time = toc
figure(3)
subplot(2,1,1)
hold on
surfc(x, y, -f)
shading interp
plot3(xopt,yopt,-fopt,'marker','o','MarkerSize',5,'MarkerFaceColor','r')
title('bounded inputs with more iterations')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
PLOTS:
plot 1 statistical 1
plot 2 statistical 2
plot 3 statistical 3
ERRORS:The error i have faced is the surface of the plot is not visible that error should be solved with the help of support persons.
COCLUSION:Thus the codes is created successfully for finding the maxima value for the given function and plotted by using the matlab. Increasing the number of iteration is decreasing the search space for right value also use the genatic algoritm is utilized and providing the necessary examples.
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...
Project 2
AIM: To develop the forward energy-based fuel Consumption model of a P1 hybrid vehicle by using the matlab and simulink. Overview: 1. Hybrid Electric vehicle: Using the Two or more energy sources to propulsion system in driving is called the Hybrid Electric Vehicle. Conventionally,petroleum fuel based energy source (Petrol,deisel,etc..)via…
30 Jun 2022 03:17 PM IST
Project 2 Adaptive Cruise Control
EV BATCH17 AIM: To develop a model of adaptive cruise control by using the matlab. Objective: Development of a MATLAB Simulink Model for Adaptive Cruise Control feature as per the requirement document following Model Based Development(MBD) related process.SLDD creation,configuration parameter changes,Model advisor check…
27 Jun 2022 07:56 AM IST
Project 1 (Mini Project on Vehicle Direction Detection
AIM: To develop the model of vehicle direction by using the matlab. OBJECTIVE: The objective of this project is to create a MBD complaint MATLAB Simulink model for a vehicle direction dectection as per the requirement specified. Tag the requirements to the simulink model;Requirement 1 & Requirement 2 are tagged…
26 Jun 2022 06:30 AM IST
Project 2 Thermal modeling of battery pack
EV BATCH17 AIM: To design a 10 series lithium ion battery model,simulate the thermal effects by using the matlab. abstract: Lithium ion (Li-ion) battery pack is a complex system consisting of numerous cells connected in parallel and series. The performance of the pack is highly dependent on the health of each individual…
18 Jun 2022 09:46 AM 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.