Challenge

Week 4.1 - Genetic Algorithm

To write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function and to expalin the concept of genetic algorithm and also to explain the syntax for ga in MATLAB.

And to plot graphs for all 3 studies and for F maximum vs no. of iterations.  

Stalagmite code for local maxima 

clear all
close all
clc

% Defining our search space
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);

%Creating a 2Dimensional mesh
[xx yy] =meshgrid(x, y);

 

% Evaluating the stalgamite 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(xx,yy,-f)
shading interp

[inputs, fval]= ga(@stalagmite,2);

Main stalagmite code function are..,

function [GA] = stalagmite(input_vector)


 x=input_vector(1);
 y=input_vector(2);

term1 = pi*5.1*x;
term2 = pi*5.1*y;
term3 = ((x-0.0667)^2/0.64);
term4 = ((y-0.0667)^2/0.64);
term5 = (-4)*log(2);

xf1 = (sin(term1+0.5)).^6;

yf1 = (sin(term2+0.5)).^6;

xf2 = exp(term5*term3);

yf2 = exp(term5*term4);


GA =-(xf1*yf1*xf2*yf2);
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.