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

02D 03H 29M 40S

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. Amit Kumar/
  3. Week 4 - Genetic Algorithm

Week 4 - Genetic Algorithm

AIM:-  To optimise the stalagmite function and find the global maxima of the function.   OBJECTIVE:-  . expalin the concept of genetic algorithm in your own words and also explain the syntax for ga in MATLAB in your report.   .Plot graphs for all 3 studies and for…

    • Amit Kumar

      updated on 09 Jan 2021

    AIM:-

     To optimise the stalagmite function and find the global maxima of the function. 

     OBJECTIVE:-

     . expalin the concept of genetic algorithm in your own words and also explain the syntax for ga in MATLAB in your report.

      .Plot graphs for all 3 studies and for F maximum vs no. of iterations.

     

    INTRODUCTION:-

    . The genetic algorithm GA is a method for solving both constrained and unconstrained optimisation problem that is based on natural selection, the process that drives biologica evolution. GA repeatedly modified the populaton of individual solutions.

     .At each step,the genetic alogrithm selects individual at random from the current population to be parents and uses them to produce children for the next generation over successive generation, the population evolves towards an optimal solution.

     .GA can be applied to solved a variety of optimization problems that are not well suited for standard optimazation algorithms,including problems in which the objective function is discontinuous, non differentiable, stochastic, highly non linear.

     .The GA uses 3 main types of rules at each step to create the next generation from the current population:

         

                . Selection rule selects the individuals, called parents, that contribute to the population at the next generation.

                . crossover rules combine two parents to from children for the next generation.

                . Mutation rules apply random changes to individual parents to from children.

     

                 

      PROCEDURE:-

     1. intitially salalagmite function is defined in a seperate script.

     2.  A negative sign is used in fornt of the function to obtain maxima of the function rather minima.

     3. A neseted for loop is utilzed to iterate each of the elements.

     4.GA is used to determine the optimal of the function

     5. plot is generated for different cases.

     

     The three cases considered are:

     1. unbounded inputs

     2. Bounded inputs - restricated with upper and lower bounds

     3. Bounded inputs with options - increasing no of iteratons by giving population size.

     

      syntax:_- GA

          

    x = ga(fun,nvars)
    x = ga(fun,nvars,A,b)
    x = ga(fun,nvars,A,b,Aeq,beq)
    x = ga(fun,nvars,A,b,Aeq,beq,lb,ub)
    x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)
    x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
    x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon)
    x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,options)
    x = ga(problem)
    [x,fval] = ga(___)
    [x,fval,exitflag,output] = ga(___)
    [x,fval,exitflag,output,population,scores] = ga(___)
     
     
     DESCRIPTION
        

      x = ga(fun,nvars) finds a local unconstrained minimum, x, to the objective function, fun. nvars is the dimension (number of design variables) of fun.

      x = ga(fun,nvars,A,b) finds a local minimum x to fun, subject to the linear inequalities A*x ≤ b. ga evaluates the matrix  product A*x as if x is transposed (A*x').

      x = ga(fun,nvars,A,b,Aeq,beq) finds a local minimum x to fun, subject to the linear equalities Aeq*x = beq and A*x ≤ b.(Set A=[] and b=[] if no linear inequalities exist.) ga evaluates the matrix product Aeq*x as if x is transposed   (Aeq*x').

          
      Example:-


       x = ga(fun,nvars,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that a solution is found in the range lb ≤ x ≤ ub. (Set Aeq=[] and beq=[] if no linear equalities exist.)

     Stalagmite Function

     

     .A Stalagmite function which is represented by these formulas & equations is used to obtain a stalagmite structure

             

     1). This is then ran through the genetic algorithm command in MATLAB to optimizalution and find more fit value hrough random selection.

        

     

         

      I. The above function defines the stalagmite function which will be used in the main function.

      ii. The input vectors 'x' and 'y' will be assigned with the required values in the main function.

      iii.Negative sign used in the last line is used to maximize the stalagmite function.

       

    • The initial code for generating stalagmite function through GA is :- 

        

           It gives the output as :-

           

     

     

      .The code runs the stalagmite function through the GA and produces results for minimum value , for global maxima we need the global optimization tool box by matlab .but a simple trick is to put minus sign before the equation output value which gives the negative value, which is actually opposite of minimum and i.e the global maxima of the stalagmite function as shown above. 

      .But the genetic algorithm in this case produces random out every time its made to run .hence to optimize it further several studies are done further to get a more fit value

     

      Studies for optimization of stalagmite function to find Global Maxima :- 

       

    clear all
    close all
    clc
    
    x = linspace(0,0.6,150);
    y = linspace(0,0.6,150);
    
    
    
    %creating two dimensional mesh
    [xx,yy]=meshgrid(x,y);
    
    num_cases=50
    %evaluting 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) = get_stalagmite(input_vector);
    end
    end
       
    tic
    %study 1 = satistical behaviour
    
    
    for i = 1:num_cases
        [inputs,fopt(i)] = ga(@get_stalagmite, 2);
        xopt(i) = inputs(1);
        yopt(i) = inputs(2);
    end
    
    study1_time= toc
    %ploting
    figure(1)
    subplot(2,1,1)
    hold on
    surfc(xx, yy, f)
    shading interp
    hold on
    plot3(xopt,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
    title('unbonded inputs')
    subplot(2,1,2)
    plot(fopt)
    xlabel('iterations')
    ylabel('function minimum')
    
    tic
    % study 2_statistical behavior_with upper and lower bounds
    for i = 1:num_cases
    [inputs,fopt(1)] =  ga(@get_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 minimum')
    
    %study 3_increasing GA iterations
    options = optimoptions('ga')
    options = optimoptions(options,'populationsize',180)
    
    tic
    for i=1:num_cases
    [inputs,fopt(i)]=ga(@get_stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
    end
    study3_time = toc
    figure(3)
    subplot(2,1,1)
    hold on
    surfc(xx,yy,-f)
    hold on
    shading interp
    plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
    title('bounded inpiuts ')
    subplot(2,1,2)
    plot(-fopt)
    xlabel('iteration')
    ylabel('function maximum')
    
    
    
    
    
    

     STEP WISE CODE EXPLATION

      .200 cases are assigned to run through the stalagmite function & genetic algorithm 

      .Stalagmite function is called then from the code shown later which produces the stalagmite and is passed to the genetic algorithm in the main command shown above

      .Study 1 : 

      .Is done for 200 iterations as mentioned and further genetic algorithm is used for the stalagmite function comprising of the  equations shown above in the picture with its 2 variables . 

      .The syntax used in this one is :  [inputs , fopt(i)] = ga(@stalagmite, 2);

      .which is : x = ga(fun,nvars) finds a local unconstrained minimum, x, to the objective function, fun. nvars is the dimension number of design variables) of fu

      .The study is timed using tic toc commands 

      .The study 1 is done for statistical behaviour of the stalagmite function and its values are random and changes and not much optimized .

     . markers are plotted using plot3 command over the fitness values obtained in the first study and also a 2d graph is shown for a  more understanding to its global maxima.

     . for first study there is a high variation

     . Study 2 : 

     . This study is done for further optimization of the stalagmite function . 

     . Similar approach as first study is made and the syntax for GA is further modified and upper and lower bounds are assigned from 0-1 for both x and y. 

      [inputs , fopt(i)] = ga(@stalagmite, 2, [],[] ,[],[],[0;0],[1;1]);

     .syntax - x = ga(fun,nvars,A,b,Aeq,beq,lb,ub)  , where A ,B and Aeq and beq are blanks . lb and ub represents lower and upper  bounds respectively. 

     .It defines a set of lower and upper bounds on the design variables, x, so that a solution is found in the range lb ≤ x ≤ ub. (Set Aeq=[] and beq=[] if no linear equalities exist.)

    . The rest approach is same as study 1 .

     .Study 3 :

    . Study 2 sucessfully optimized the function but it can still be further optimized, hence we do further one more study where we increase the ga populationsize by modifying the syntax for GA and set it to 500 from default 50

     .[inputs , fopt(i)] = ga(@stalagmite, 2, [], [] ,[],[],[0;0],[1;1],[],[],options); 

     .Syntax - x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options) minimizes with the default optimization parameters replaced by values in options. (Set nonlcon=[] if no nonlinear constraints exist.) Create options using optimoptions.

     .where values not placed are simply replaced with blank brackets .

     .Again similar approach as study 1 is followed.

     

     .CALLING STALGMITE FUNCTION:-

      . This is stalagmite function developed from the formulas and equations above to produce stalagmite and its used in the GA and it also follows from the get_stalagmite funtion and then passed through studies conducted.

      

       . For study 1 below it is seen the value varies alot in negative direction . (global maxima)

     

        

        

       . Time study 1

        

        .For study 2 the value is optimized and the global maxima is bounded between 0-1 and it still needs more optimization and shows the global maxima value ranges between -1 and -0.9 majorly

        

     

       . Study time 2.

       

      3. In study 3 the genetic algorithm has highly optimized the value for 150 iterations and 180 population size .Our global maxima range lies between - 0.96932615 to -0.96932614 even though it still shows slight variation as can be       seen in the 2d  graph. but the stalagmite algorithm is considerably optimize.

      

      Study time3:-

      

    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 Amit Kumar (52)

    Week - 9 Material Modeling from Raw Data

    Objective:

    AIM:- Material Modeling from Raw Data OBJECTIVE:-  Using the given video link, extract the data from the figure, and used it for validation. Create a material model for the Dogbone specimen using the diagram of the true stress-strain curve (graphite iron). From the above condition simulate…

    calendar

    29 Oct 2023 12:33 PM IST

    • CSS
    • FEA
    Read more

    Week-6 Calculate the Stretch Ratio by comparing the ELFORM (-2,-1,1,2) with Ogden_Material Model.

    Objective:

    AIM:-calculate the Stretch Ratio by comparing the ELFORM OBJECTIVE:- Create a block of 10mmx10mmx10mm dimension with 10 elements for each direction and use the material card attached (Ogden_Material.k) that is representative of the material properties from the above figure. Use appropriate boundary conditions to simulate…

    calendar

    27 Oct 2023 05:47 PM IST

      Read more

      Week - 5 - Modelling Spotwelds

      Objective:

      AIM:-Modelling SpotweldsOBJECTIVE:-In this assignment, you will model spot welds for the given assembly of parts and run a crash test similar to the one in assignment 4. Details about the spotweld location is in the image below. The yellow line signifies the spotweld directions. You need to use 3-7 spot welds along this…

      calendar

      26 Oct 2023 08:40 PM IST

        Read more

        Week - 4 - Crash Box Simulation

        Objective:

        AIM:- Crash Box Simulation OBJECTIVE:-In this assignment, the student needs to simulate a crash test for a crash box for which mesh is given. A crash box is a highly energy-absorbing structure that crashes on application of loads and reduces impact on other components nearby. A full-fledges crashbox is a highly sophisticated…

        calendar

        26 Oct 2023 02:15 PM IST

        • BIM
        • CAE
        • CFD
        • CSS
        • DEM
        • FEA
        • GIS
        • HEV
        • LS-DYNA
        • MBD
        Read more

        Schedule a counselling session

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

        Related Courses

        coursecard

        Design loads considered on bridges

        Recently launched

        10 Hours of Content

        coursecard

        Design of Steel Superstructure in Bridges

        Recently launched

        16 Hours of Content

        coursecard

        Design for Manufacturability (DFM)

        Recently launched

        11 Hours of Content

        coursecard

        CATIA for Medical Product Design

        Recently launched

        5 Hours of Content

        coursecardcoursetype

        Accelerated Career Program in Embedded Systems (On-Campus) Courseware Partner: IT-ITes SSC nasscom

        Recently launched

        0 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.