All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Genetic Algorithm: Aim:– To calculate the generic algorithm for calculating the local maxima and calculating the optimum values for a given function. Introduction:– Generic algorithm uses the method of random sampling. This method of solving constrained and unconstrained problems which are based upon…
Raja Narendra Bandaru
updated on 18 Nov 2021
Genetic Algorithm:
Aim:–
To calculate the generic algorithm for calculating the local maxima and calculating the optimum values for a given function.
Introduction:–
Generic algorithm uses the method of random sampling. This method of solving constrained and unconstrained problems which are based upon selection. Generic algorithm is widely used to solve the optimization problems in different fields. Generic algorithm starts with an initial set of random solutions called Population. Each individual in the population is called chromosome representing a solution to the problem at hand. The chromosome evolves through the successive iterations, called generations. During each generation, the chromosomes are evaluated using some measures of fitness. To create a new generation, new chromosome are formed by either merging two chromosomes from current generation using a crossover operator or modifying a chromosome using mutation operator. A new generation is formed by selecting according to fitness values and rejecting others so as to keep the population size constant. Staligmite function is the mathematical model for generating the local minima and maxima.
Code for Staligmite function-
function[Z] = staligmite(input_vector)
x = input_vector(1);
y = input_vector(2);
f1x = (sin((5.1*(pi.*x))+0.5))^6;
f1y = (sin((5.1*(pi.*y))+0.5))^6;
f2x = exp((-4*log(2)).*((x-0.0667).^2/(0.64)));
f2y = exp((-4*log(2)).*((y-0.0667).^2/(0.64)));
%[Z] = (f1x.*f2x.*f1y.*f2y);
fx = -f1x.*f2x;
fy = f1y.*f2y;
[Z] = (fx.*fy);
end
Maxima is a function to represent the change of values from positive to negative. Hence, to find out the maxima of a given function, one of the value in the function[f(x)] is taken as negative. So that negative values of function minimum are obtained and the maxima can be determined. (i.e. Maxima = -Minima).
Main Code for GA-
clear all
close all
clc
x = linspace(0,0.6,100);
y = linspace(0,0.6,100);
n_var = 100;
[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) = staligmite(input_vector);
end
end
tic
for i = 1:n_var
[input,fopt(i)] = ga(@staligmite,2);
xopt(i) = input(1);
yopt(i) = input(2);
end
studytime_case1 = toc
figure(1)
subplot(2,1,1)
surfc(x,y,f)
shading interp
hold on
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(fopt)
title('Unbounded Inputs');
xlabel('Iterations');
ylabel('Function minimum');
%Study case 2- Bounded inputs.
tic
for i = 1:n_var
[input,fopt(i)] = ga(@staligmite,2,[],[],[],[],[0;0],[0.6;0.6]);
xopt(i) = input(1);
yopt(i) = input(2);
end
studytime_case2 = toc
figure(2)
subplot(2,1,1)
surfc(x,y,f)
shading interp
hold on
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(fopt)
title('Bounded Inputs');
xlabel('Iterations');
ylabel('Function minimum');
%Study case 3- Bounded Inputs with Popolation size
options = optimoptions('ga');
options = optimoptions(options,'PopulationSize',500);
tic
for i = 1:n_var
[input,fopt(i)] = ga(@staligmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
xopt(i) = input(1);
yopt(i) = input(2);
end
studytime_case3 = toc
figure(3)
subplot(2,1,1)
surfc(x,y,f)
shading interp
hold on
plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(fopt)
title('Bounded Inputs with Population Size');
xlabel('Iterations');
ylabel('Function minimum');
Results-
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
Element Creation Challenge- AIM- To mesh the Given component with the Size of 5 Units and create 1D elements on the following component with given cross-section and DOF. OBJECTIVE- a. Rod element:- Translational DOF should be Constrained with RBE2 link Cross-Section: BOX- Dimension a= 12 mm …
22 Dec 2021 08:28 PM IST
Project 1 - Parsing NASA thermodynamic data
PARSING NASA THERMODYNAMIC DATA AIM- To calculate thermodynamic properties of various gas species using MATLAB to parse the NASA Thermodynamic data file which is already provided. OBJECTIVE- Write a function that extracts the 14 coefficients and calculates the Enthalpy, entropy, and specific heats for all the…
29 Nov 2021 12:10 PM IST
Week 4.1 - Genetic Algorithm
Genetic Algorithm: Aim:– To calculate the generic algorithm for calculating the local maxima and calculating the optimum values for a given function. Introduction:– Generic algorithm uses the method of random sampling. This method of solving constrained and unconstrained problems which are based upon…
18 Nov 2021 12:08 PM IST
Week 3 - Solving second order ODEs
SOLVING SECOND ORDER ODE's AIM: Create Simulation of Simple pendulum With MATLAB as solution for second order ODE. OBJECTIVE: Write a program that solves second order ODE for the simple pendulum with given conditions like damping coeffiecient, lenght of pendulum, gravity and mass. GIVEN VALUES: Simulate…
01 Nov 2021 07:29 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.