Placement 2025 Scholarship: Your Future Starts Here | 6 Guaranteed Job Interviews | Limited to 100 seats. Apply Now

06D 10H 05M 27S

Menu

Executive Programs

Workshops

Projects

Blogs

Careers

Placements

Student Reviews


For Business


More

Academic Training

Informative Articles

Find Jobs

We are Hiring!


All Courses

Choose a category

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

All Courses

All Courses

logo

CHOOSE A CATEGORY

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

Top Job Leading Courses

Automotive

CFD

FEA

Design

MBD

Med Tech

Courses by Software

Design

Solver

Automation

Vehicle Dynamics

CFD Solver

Preprocessor

Courses by Semester

First Year

Second Year

Third Year

Fourth Year

Courses by Domain

Automotive

CFD

Design

FEA

Tool-focused Courses

Design

Solver

Automation

Preprocessor

CFD Solver

Vehicle Dynamics

Machine learning

Machine Learning and AI

POPULAR COURSES

coursePost Graduate Program in Hybrid Electric Vehicle Design and Analysis
coursePost Graduate Program in Computational Fluid Dynamics
coursePost Graduate Program in CAD
coursePost Graduate Program in CAE
coursePost Graduate Program in Manufacturing Design
coursePost Graduate Program in Computational Design and Pre-processing
coursePost Graduate Program in Complete Passenger Car Design & Product Development
Executive Programs
Workshops
For Business

Success Stories

Placements

Student Reviews

More

Projects

Blogs

Academic Training

Find Jobs

Informative Articles

We're Hiring!

phone+91 9342691281Log in
  1. Home/
  2. Syed Saquib/
  3. Week 4.1 - Genetic Algorithm

Week 4.1 - Genetic Algorithm

Introduction to optimization:   Optimization with MATLAB Optimization deals with selecting the best option among a number of possible choices that are feasible or don't violate constraints. Genetic algorithm- Genetic Algorithms(GAs) are adaptive heuristic search algorithms that belong to the larger…

  • MATLAB
  • Syed Saquib

    updated on 27 Apr 2022

Introduction to optimization:

 

  • Optimization with MATLAB Optimization deals with selecting the best option among a number of possible choices that are feasible or don't violate constraints.

Genetic algorithm-

Genetic Algorithms(GAs) are adaptive heuristic search algorithms that belong to the larger part of evolutionary algorithms. Genetic algorithms are based on the ideas of natural selection and genetics.

These are intelligent exploitation of random search provided with historical data to direct the search into the region of better performance in solution space. 

They are commonly used to generate high-quality solutions for optimization problems and search problems.

Advantages-

  • The Concept of Genetic algorithm is easy to understand.
  • Genetic algorithm is robust with respect to local maxima/minima.
  • Genetic algorithm is good for noisy environments.
  • The random mutation guarantees in a wide range of solutions.

Disadvantages-

1 GA implementation is still an art.

2 GA requires less information about the problem, but designing an objective function and getting the representation.

3 GA is computationally expensive i.e. time-consuming. 

 

Aim-To write code to calculate global maxima using algorith, using matlab

The stalagmite function is as follows

Tha above function is defined in the stalagmite function in matlab as shwon below

function[f]=stalagmite(input_vector)  %stalagmite function wih input_vector which contain the x ar
x=input_vector(1);
y=input_vector(2);
f1=(sin(5.1*pi*x+0.5))^6;
f2=(sin(5.1*pi*y+0.5))^6;
f3=exp(-4*log(2)*(x-0.0067)^2/0.64);
f4=exp(-4*log(2)*(y-0.0067)^2/0.64);
f=-(f1*f2*f3*f4)
end
 
The format for writing genetic algorith in matlab is 
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options)
X= minama point
a and b are used to indicate the inequalities that exist in the function
fun-function
Aeq and Beq also denotes the inequalities
nvars denotes no variables used
lb-=lower bound
up-upper bound
 
1) First iteration:-
In the first iteration the behaviour of teh algorithm is studied by not defining the limits.
 
Program-
 
clear all
close all
clc
num_cases=50 % GA runs for 50 iterations
%defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
%creating a 2D mesh
[xx yy]=meshgrid(x,y);
%evaluating 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
surfc(x,y,f)
tic % study time count start
for i=1:num_cases
[inputs,f_opt(i)]=ga(@stalagmite,2);
x_opt(i)=inputs(1);
y_opt(i)=inputs(2);
end
f_opt=-f_opt;
study1_time = toc %study time count end
subplot(2,1,1)
hold on
surfc(x,y,-f) % genertaion of stalagmite
shading interp %to bring visually smooth curve witout mesg=hlines
plot3(x_opt,y_opt,f_opt,'marker','o','markersize',4,'markerfacecolor','r')
title('Unbounded inputs')
subplot(2,1,2)
plot(f_opt) % plot of opt_f for every iterations
xlabel('Number of iterations---->')
ylabel('Funcion Max-->')
 
2) Second iteratio:-
Here the upper and lower bounds are defined soa s to know the boundries within the global maxima lies.
 
Program-
 
clear all
close all
clc
num_cases=50 % GA runs for 50 iterations
%defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
%creating a 2D mesh
[xx yy]=meshgrid(x,y);
%evaluating 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
surfc(x,y,f)
tic % study time count start
for i=1:num_cases
[inputs2,f_opt2(i)]=ga(@stalagmite,2,[],[],[],[],[0 0],[1 1]); %lb of variables of x and Y is (0 0) %ub of variables of x and Y is (1 1)
x_opt2(i)=inputs2(1); 
y_opt2(i)=inputs2(2);
end
f_opt2=-f_opt2;
time_study2=toc
figure(2)
subplot(2,1,1)
hold on
surfc(x,y,-f) % genertaion of stalagmite
shading interp %to bring visually smooth curve witout mesg=hlines
plot3(x_opt2,y_opt2,f_opt2,'marker','o','markersize',4,'markerfacecolor','r')
title('Bounded inputs')
subplot(2,1,2)
plot(f_opt2) % plot of opt_f for every iterations
xlabel('iterations')
ylabel('Funcion Minumum')
 
3) Thrid iteration:-
In this itetarion population size is increased as on to converage to the global maxima
 
Program-
 
clear all
close all
clc
num_cases=50 % GA runs for 50 iterations
%defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
%creating a 2D mesh
[xx yy]=meshgrid(x,y);
%evaluating 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
surfc(x,y,f)
options=optimoptions ('ga')
options=optimoptions(options,'PopulationSize',500);
tic % study time count start
for i=1:num_cases
[inputs3,f_opt3(i)]=ga(@stalagmite,2,[],[],[],[],[0 0],[0.6 0.6],[],[],options);
x_opt3(i)=inputs3(1);
y_opt3(i)=inputs3(2);
end
f_opt3=-f_opt3;
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,-f) % genertaion of stalagmite
shading interp %to bring visually smooth curve witout mesg=hlines
plot3(x_opt3,y_opt3,f_opt3,'marker','o','markersize',4,'markerfacecolor','r')
title('Bounded inputs with optioptims function')
subplot(2,1,2)
plot(f_opt2) % plot of opt_f for every iterations
xlabel('iterations')
ylabel('Funcion Minumum')
time_study3=toc
rng('default')
 
Results
 
1) First iteration
2) Second iteration
 
3) Third iteration (population size 500)
 
 

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.

Please  login to add a comment

Other comments...

No comments yet!
Be the first to add a comment

Read more Projects by Syed Saquib (43)

Week - 4 - 2D meshing for Plastic components

Objective:

calendar

14 Feb 2024 04:24 PM IST

    Read more

    Week 3 - 2D meshing for Sheet metal

    Objective:

     

    calendar

    14 Feb 2024 04:10 PM IST

      Read more

      Project

      Objective:

      AIM: To carry out a system-level simulation of an All-Terrain Vehicle (ATV). OBJECTIVES : To carry out a Simulation of ATV. To prepare a technical report explaining the model properties & comments on the results.   THEORY : All-Terrain Vehicle (ATV) An All-Terrain Vehicle (ATV), also known as a light utility…

      calendar

      03 Jan 2024 10:45 AM IST

      • HTML
      Read more

      Project 1

      Objective:

        Aim : Develop a double-acting actuator model using Simscape Multibody and Simscape components.   Objective : The mechanical system of the cylinder needs to be built using Simscape Multibody library components/blocks, and the hydraulic system needs to be modeled using Simscape library physical components. Theory : The…

      calendar

      16 Oct 2023 03:59 PM IST

      • HTML
      Read more

      Schedule a counselling session

      Please enter your name
      Please enter a valid email
      Please enter a valid number

      Related Courses

      coursecard

      Simulation and Design of Power Converters for EV using MATLAB and Simulink

      4.9

      22 Hours of Content

      coursecard

      Introduction to Hybrid Electric Vehicle using MATLAB and Simulink

      4.8

      23 Hours of Content

      coursecardcoursetype

      Mechanical Engineering Essentials Program

      4.7

      21 Hours of Content

      coursecard

      Vehicle Dynamics using MATLAB

      4.8

      37 Hours of Content

      coursecard

      Introduction to CFD using MATLAB and OpenFOAM

      4.8

      13 Hours of Content

      Schedule a counselling session

      Please enter your name
      Please enter a valid email
      Please enter a valid number

      logo

      Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.

      https://d27yxarlh48w6q.cloudfront.net/web/v1/images/facebook.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/insta.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/twitter.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/youtube.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/linkedin.svg

      Our Company

      News & EventsBlogCareersGrievance RedressalSkill-Lync ReviewsTermsPrivacy PolicyBecome an Affiliate
      map
      EpowerX Learning Technologies Pvt Ltd.
      4th Floor, BLOCK-B, Velachery - Tambaram Main Rd, Ram Nagar South, Madipakkam, Chennai, Tamil Nadu 600042.
      mail
      info@skill-lync.com
      mail
      ITgrievance@skill-lync.com

      Top Individual Courses

      Computational Combustion Using Python and CanteraIntroduction to Physical Modeling using SimscapeIntroduction to Structural Analysis using ANSYS WorkbenchIntroduction to Structural Analysis using ANSYS Workbench

      Top PG Programs

      Post Graduate Program in Hybrid Electric Vehicle Design and AnalysisPost Graduate Program in Computational Fluid DynamicsPost Graduate Program in CADPost Graduate Program in Electric Vehicle Design & Development

      Skill-Lync Plus

      Executive Program in Electric Vehicle Embedded SoftwareExecutive Program in Electric Vehicle DesignExecutive Program in Cybersecurity

      Trending Blogs

      Heat Transfer Principles in Energy-Efficient Refrigerators and Air Conditioners Advanced Modeling and Result Visualization in Simscape Exploring Simulink and Library Browser in Simscape Advanced Simulink Tools and Libraries in SimscapeExploring Simulink Basics in Simscape

      © 2025 Skill-Lync Inc. All Rights Reserved.

                  Do You Want To Showcase Your Technical Skills?
                  Sign-Up for our projects.