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

01D 05H 42M 08S

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. Aniket Kumbhar/
  3. Project 1 - MATLAB - Anonymous function stalagmite with Genetic Algorithm.

Project 1 - MATLAB - Anonymous function stalagmite with Genetic Algorithm.

 AIM:  Make a Mat Lab code to solve anonymous function stalagmite with Genetic Algorithm and generate plot with finding global maxima.                     OBJECTIVE:                â€¦

    • Aniket Kumbhar

      updated on 06 Jun 2022

     AIM:  Make a Mat Lab code to solve anonymous function stalagmite with Genetic Algorithm and generate plot with finding global maxima.                    

    OBJECTIVE:

                         Make a Mat Lab code to solve anonymous function stalagmite with Genetic Algorithm and generate plot. Explaining the concept and studying the behaviour of genetic algorithm to achieve constant global maxima.

    SOLUTION:

                          A Mat Lab code was written for curve fit. To find fitting the liner and cubic polynomials to identify errors generated in original curve vs. fitted curve. Further code generates a plot for it. With respect to the input variables given.

    EXPLANATION:

                               Genetic Algorithm in Mat-Lab use for solve analysis and search problems. Genetic Algorithm is theory of Charles Darwin's natural evolution. Genetic Algorithm involves the process of selection where the fittest individual are selected for reproduction in order to produce offspring’s of next generation (i.e., traits are passed to one generation to another generation).

                              A genetic algorithm (GA) is a method for solving both constrained and unconstrained optimization problems based on a natural selection process that mimics biological evolution. The algorithm repeatedly modifies a population of individual solutions. At each step, the genetic algorithm randomly selects individuals from the current population and uses them as parents to produce the children for the next generation. Over successive generations, the population "evolves" toward an optimal solution. You can apply the genetic algorithm to solve problems that are not well suited for standard optimization algorithms, including problems in which the objective function is discontinuous, no differentiable, stochastic, or highly nonlinear. Genetic Algorithm is method of solving constrained and unconstrained optimization problem. Optimization is the making the best and effective use of resource.

    Constrained Optimization: It is process of optimizing objective function with respect to some variable.

    Unconstrained Optimization: In this optimization deals with minimizing an objective function depending on real variable.

                              Genetic Algorithm takes random samples, i.e., it takes random inputs and based on that random inputs it evaluates the function and then it sticks on natural selection where it takes two generation and mutate them and do crossover and create a new generation which is hopefully better. The above concept works in executing the 'ga' function in matlab and it optimizes the stalagmite function.  

    Stalagmite Function –

    From this function we can obtain some geometrical structure using math function.

    Program For Stalagmite Function –

     

    function f = stalagmite(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);

    f = -(f1x.*f1y.*f2x.*f2y);

    end

     

     Here,

    we created the stalagmite function , ‘stalagmite’ and passing ‘input_ vector’ as the arguments for the variable x and y , then value of input vector is added in variable x and y. user define mathematical stalagmite function is defined and variable f is used to define then the sol. Is, multiplied by 1 to get downward stalagmite.

     

    The main program   â€“

    %to solve the genetic algorithm
    
    close all
    clear all
    clc
    
    %1 the dimentional array 
    
    x=linspace(0,0.6,150);
    y=linspace(0,0.6,150);
    
    %storing 150 values of x and y between 0 and 0.6
    
    %runing Genetic algorithm  for 50 times 
    num_case = 50;
    
    %cearting 2 dimentional array using mesh 
    
    [xx, yy] = meshgrid(x,y);
    
    %each of value of x,y creating array called input vector 
    %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) = stalagmite(input_vector);
        end
    end
    
    
    %Case study 1 
    %statistical behaviour of Genetic algorithm 
    %with providing boundries 
    
    tic % starting stopwatch timer 
    
    for i = 1:num_case 
        [input,fopt(i)] = ga(@stalagmite,2);
        xopt(i)= input(1);
        yopt(i)= input(2);
    end
    
    % reading the time taken by stopwatch
    study_time1 = toc
    
    %ploting case study 
    
    figure(1)
    subplot(2,1,1)
    surfc(xx,yy,-f)
    
    %converts the 2nd plot into 3d plot
    
    xlabel('x values')
    ylabel('y values')
    zlabel('z values') 
    shading interp
    
    %control the color shading of surface of surfec by interpolating the
    %colormap index
    hold on 
    plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
    title('Unbounded Inputs')
    subplot(2,1,2)
    plot(-fopt)
    xlabel('iteration')
    ylabel('function main')
    
    
    %case study 2 
    %with Bounded conditions ( upper bound and lower)
    tic
    for i = 1:num_case;
        [input,fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0,0],[0.6,0.6]);
        xopt(i)= input(1);
        yopt(i)= input(2);
    end
    
    study_time2 = toc
    figure (2)
    subplot(2,1,1)
    surfc(xx,yy,-f)
    shading interp
    hold on
    plot3(xopt,yopt,-fopt,'marker','o','markersize',5)
    title('Bounded Inputs')
    xlabel('x values')
    ylabel('y values')
    zlabel('z values')
    
    subplot(2,1,2)
    plot(-fopt)
    xlabel('Interations')
    ylabel('Function minimum')
    zlabel('f values')
    
    
    %case study 3 
    %with increasing the fenetic algoritham iteration
    %Bounded conditions ( upper bound and lower bound)
    
    option = optimoptions('ga')
    option = optimoptions(option,'PopulationSize',300);
    %creates a set of the options with each option set to its defelt value.
    %population size is set to 300
    
    tic
    for i = 1:num_case;
        [input,fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0,0],[0.6;0.6],[],[],option);
        xopt(i)= input(1);
        yopt(i)= input(2);
    end
    
    study_time3 = toc
    figure (3)
    subplot(2,1,1)
    surfc(xx,yy,-f)
    shading interp
    hold on
    plot3(xopt,yopt,-fopt,'marker','o','markersize',5)
    title('Bounded Inputs with Population Size')
    xlabel('x values')
    ylabel('y values')
    zlabel('z values')
    
    subplot(2,1,2)
    plot(-fopt)
    xlabel('Interations')
    ylabel('Function minimum')
    zlabel('f values')
    title('Maximum Iteration')
    
    
    
    
    function - 
    
    
    function f = stalagmite(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);
    
    f = -(f1x.*f1y.*f2x.*f2y);
    
    end
    
    

    Procedure –

    The program starts with command of clear all, close all, clc.  Then it stores 150 values of x and y using linspace command. The num_space variable used for genetic algorithm for 50 times in order to global maxima. After that creating the 2D array by mesh grid command. Creating 2D array of xx’ and yy’ array using counter. Providing the values to the variable 1 and 2. Using for loop. Starting for loop from 1 to length of xx’ array using counter ’i’. the nested loop is created using the counter ‘j’ saving the values of xx’ and yy’ in variable input vector 1 & 2.  The final stage is to be call function ‘stalagmite’.

     %to solve the genetic algorithm

    close all

    clear all

    clc

    %1 the dimensional array

    x=linspace(0,0.6,150);

    y=linspace(0,0.6,150);

    %storing 150 values of x and y between 0 and 0.6

    %runing Genetic algorithm  for 50 times

    num_case = 50;

    %cearting 2 dimensional array using mesh

    [xx, yy] = meshgrid(x,y); 

    %each of value of x,y creating array called input vector

    %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) = stalagmite(input_vector);

        end

    end

     

    We are using the stopwatch timer ‘tic’ for solving the statistical behaviour of genetic algorithm. Starting ‘for’ loop from 1 to length of num_case variable ‘I’. Calling the genetic algorithm ‘ga’ an inbuilt matlab function. To solve ‘stalagmite’ function. ‘Input’ is the array to store optimum values of the variable. The input and fopt area outputs of the genetic algorithm. Saving the time taken by the program in the variable ‘study_time1’. Plotting the case study 1 figure create the 3d surface plot. With the solid edge colour and face colour. Then labelling and x, y axis naming title.

      

    %Case study 1

    %statistical behaviour of Genetic algorithm

    %with providing boundaries

    tic % starting stopwatch timer

    for i = 1:num_case

        [input,fopt(i)] = ga(@stalagmite,2);

        xopt(i)= input(1);

        yopt(i)= input(2);

    end

     

    % reading the time taken by stopwatch

    study_time1 = toc

    %ploting case study

    figure(1)

    subplot(2,1,1)

    surfc(xx,yy,-f)

    %converts the 2nd plot into 3d plot

    xlabel('x values')

    ylabel('y values')

    zlabel('z values')

    shading interp

    %control the color shading of surface of surfec by interpolating the

    %colormap index

    hold on

    plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')

    title('Unbounded Inputs')

    subplot(2,1,2)

    plot(-fopt)

    xlabel('iteration')

    ylabel('function main')

    Study time = 3.2752.

    It shows that algoritham behaves when no bound are present it takes random samples bellow the searching place.

    We are using the stopwatch timer ‘tic’ for solving the statistical behaviour of genetic algorithm. Starting ‘for’ loop from 1 to length of num_case variable ‘I’. Calling the genetic algorithm ‘ga’ an inbuilt matlab function. To solve ‘stalagmite’ function. The ga syntax is used for mentioning the upper bound , lower bound. Inut is array to store the optimum values of variables. . ‘Input’ is the array to store optimum values of the variable. The input and fopt area outputs of the genetic algorithm. Saving the time taken by the program in the variable ‘study_time2’. Plotting the case study 2 figure create the 3D surface plot. With the solid edge colour and face colour. Then labelling and x, y axis naming title.

      

    %case study 2

    %with Bounded conditions ( upper bound and lower)

    tic

    for i = 1:num_case;

        [input,fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0,0],[0.6,0.6]);

        xopt(i)= input(1);

        yopt(i)= input(2);

    end

     

    study_time2 = toc

    figure (2)

    subplot(2,1,1)

    surfc(xx,yy,-f)

    shading interp

    hold on

    plot3(xopt,yopt,-fopt,'marker','o','markersize',5)

    title('Bounded Inputs')

    xlabel('x values')

    ylabel('y values')

    zlabel('z values')

    subplot(2,1,2)

    plot(-fopt)

    xlabel('Interations')

    ylabel('Function minimum')

    zlabel('f values')

    Study time 2 = 4.1148.

    It shows that after including upper bounds and lower bounds, reduces search space & gives optimum outputs.

     

    We are using the stopwatch timer ‘tic’ for solving the statistical behaviour of genetic algorithm. Starting ‘for’ loop from 1 to length of num_case variable ‘I’. Calling the genetic algorithm ‘ga’ an inbuilt matlab function. To solve ‘stalagmite’ function. The ga syntax is used for mentioning the upper bound, lower bound. Input is array to store the optimum values of variables. Providing the value of parameters ‘population size with value of 300. ‘Input’ is the array to store optimum values of the variable. The input and fopt area outputs of the genetic algorithm. Saving the time taken by the program in the variable ‘study_time3’. Plotting the case study 3 figure create the 3D surface plot. With the solid edge colour and face colour. Then labelling and x, y axis naming title.

     

     

    %case study 3

    %with increasing the fenetic algoritham iteration

    %Bounded conditions ( upper bound and lower bound)

     

    option = optimoptions('ga')

    option = optimoptions(option,'PopulationSize',300);

    %creates a set of the options with each option set to its defelt value.

    %population size is set to 300

     

    tic

    for i = 1:num_case;

        [input,fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0,0],[0.6;0.6],[],[],option);

        xopt(i)= input(1);

        yopt(i)= input(2);

    end

     

    study_time3 = toc

    figure (3)

    subplot(2,1,1)

    surfc(xx,yy,-f)

    shading interp

    hold on

    plot3(xopt,yopt,-fopt,'marker','o','markersize',5)

    title('Bounded Inputs with Population Size')

    xlabel('x values')

    ylabel('y values')

    zlabel('z values')

    subplot(2,1,2)

    plot(-fopt)

    xlabel('Interations')

    ylabel('Function minimum')

    zlabel('f values')

    title('Maximum Iteration')

     

    Study time = 12.4398.

    It shows that, after specified that results wants for population size the genetic algorithm search with more deeply to define the search space for increase in population size in genetic algorithm, it takes the 13 seconds to complete. And shows the final results for GA.

     

     

    Screen shoot while programing Errors and overcomes  -

                      Fig; screen shoot for error while program typing mistakes

     

                               Fig; screen shoot while program successfully runs  

                             

    Conclusion   –

    The code for stalagmite function by genetic algorithm has been successfully runs.

    All the results and statistical behaviour of genetic algorithm has been plotted and outcomes.

    The global maxima of stalagmite function has found.

     

    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 Aniket Kumbhar (24)

    Week 11 - Final project

    Objective:

    Aim: To Creation of CAD model considering Class A surface, Nominal thickness and Attachment strategy.   Objective: To Creation of CAD model considering Class A surface, Nominal thickness and Attachment strategy. Create thickened part using master section for reference Create the mounting features as per design guidelines…

    calendar

    05 Jan 2023 11:12 AM IST

    • CATIA
    Read more

    Hood design-Week 2

    Objective:

    HOOD DESIGN OF A CAR AIM : To design the hood of a car with the given input Outer panel and its dimensions.   Hood Introduction :   The hood (North American English) or bonnet (Commonwealth English) is the hinged cove over the engine of motor vehicles. Hoods can open to allow access to the engine compartment…

    calendar

    01 Nov 2022 10:50 AM IST

    • BIM
    • CAE
    • CFD
    • CSS
    • DEM
    • DESIGN
    • FEA
    • GIS
    • HEV
    • MBD
    Read more

    Week 8 - Challenge 4 - Bumper

    Objective:

    BUMPER DESIGN AIM: to make a model from the provided class-A surface.INTRODUCTION:CLASS-A SURFACE: a surface made by the designer which is given as an input to the plastic modeler to work on. It is aesthetic surfaceand the outer most surface.CLASS-B SURFACE: a surface below a certain thickness from the class-A…

    calendar

    18 Sep 2022 08:20 PM IST

    • BIM
    • CAE
    • CFD
    • CSS
    • DEM
    • DESIGN
    • FEA
    • GIS
    • HEV
    • MBD
    Read more

    Week 10- Assembly Workbench

    Objective:

    AIMIn this week’s assignment, you will have to create 2 assemblies according to the contentcovered in the course videos. You will be provided with 2D diagrams of the componentsand you will have to first create the individual part files and then create a completeassembly of those part files in the assembly workbench.…

    calendar

    14 Sep 2022 01:38 PM IST

    • BIM
    • CAE
    • CFD
    • CSS
    • DEM
    • FEA
    • GIS
    • HEV
    • MBD
    • QGIS
    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.