Project

genetic algorithm(GA) in MATLAB to find the maximum value on the surface

AIM:-

find the maximum value on a plane.

OBJECTIVES:-

1.making a program in MATLAB to find the maximum value on surface.

2.defining the use of genetic algorithm and how to use in MATLAB.

THEORY:-

a genetic algorithm (GA) is a metahuristic inspired by the process of natural selection that belongs to the larger class of evalutionary algorithm (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation,crossover and selection.john holland introduced genetic algorithms in 1960 based on the concept of Darvin's theory of evalution.

GA is used for optimization.as per project application GA used to find the maximum value on the surface.In a MATLAB GA will give only minimum value, by using small logic in program we can manuplate the GA and makes it to give maximum value.

By using stalagmite function surface has been plotted.

CALCULATION:-

the formula for stalagmite function

`f=f_1x+f_1y+f_2x+f_2y`

`f_1x=[sin(5.1*pi*x+0.5]^6`

`f_1y=[sin(5.1*pi*y+0.5]^6`

`f_2x=[exp(-4*ln(2)*(x-0.0667)^2/0.64)]`

`f_2y=[exp(-4*ln(2)*(y-0.0667)^2/0.64)]`

MATLAB program:-

clear all
close all
clc
% X and Y values is an array. 
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
% meshgrid was done to X and Y arrays. 
[xx yy]=meshgrid(x,y);
tic
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);
        get_stalagmite(i,j)=f(i,j);
    end
end
%program for plotting the surface and plot.
figure(1)
surf(xx,yy,-f)
shading interp
%STUDY-1
%stydey about genetic algorithm function.
[x,b]=ga(@stalagmite,2)
xlabel('X-axis')
ylabel('Y-axis')
zlabel('f')
sim1_time=toc


%STUDY-2
num_cases=50
tic
for i=1:num_cases;
    [inputs, fopt(i)]=ga(@stalagmite,2);
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
        
end
sim2_time=toc
%program for plotting the surface and plot.
figure(2)
subplot(2,1,1)
hold on
surf(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'-o','MarkerSize',5,'MarkerEdgeColor','b', 'MarkerFaceColor','r')
xlabel('x')
ylabel('y')
zlabel('f')

title('unbounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iterations')
ylabel('function minima')

%study-3
tic
for i=1:num_cases;
    [inputs fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
        xopt(i)=inputs(1);
        yopt(i)=inputs(2);
end
sim3_time=toc
%program for plotting the surface and plot.
figure(3)
subplot(2,1,1)
hold on
surf(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'-o','MarkerSize',5,'MarkerEdgeColor','b', 'MarkerFaceColor','r')
xlabel('x')
ylabel('y')
zlabel('f')

title('unbounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iterations')
ylabel('function minima')
%study3

    tic
    options = optimoptions('ga','populationsize',300);
for i=1:num_cases
    
       [inputs fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
        xopt(i)=inputs(1);
        yopt(i)=inputs(2);
end
figure(4)
%program for plotting the surface and plot.
subplot(2,1,1)
hold on
surf(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'-o','MarkerSize',5,'MarkerEdgeColor','b', 'MarkerFaceColor','r')
xlabel('x')
ylabel('y')
zlabel('f')

title('unbounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iterations')
ylabel('function minima')

sim4_time=toc

functional program for main program

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.0677)^2)/0.64);
f2y=exp(-4*log(2)*((y-0.0677)^2)/0.64);
f =-1*(f1x.*f1y.*f2x.*f2y);
end

STEP in Program:-

1.x,y are drag coefficients varies between 0 to 0.6 and taken 150 divisions.

2.used meshgrid to make a surface.

3.used stalagmite function to calculate the drag force.

4.plotted surface using surf command.

5.in study-1 used 'ga' command to get the where miximux force.

6.got some values but as per study GA picks random points, so answer might wrong.

7.in study-2 run the 50 times of GA but results are not good and results shown in below image.

in sub plot-1 GA values are not even in our surface boundaries and in subplot-2 showing iterations in X-axis, function maxima in Y-axis , the difference in Y-axis is too high.simulation time is 4.7213 sec.

8.study-2 results are not giving the perfect solution so in study-3 assign the GA with boundaries, results in below figure.

in sub plot-1 GA values are in our surface boundaries and in subplot-2 showing iterations in X-axis, function maxima in Y-axis , the difference in Y-axis is too high between iterations to iterations.simulation time is 6.5672 sec.

9.in stydy-3 results are not giving the perfect solution so in study-4 assign the GA with boundaries from stydey-3 and population size randomly increased, results in below figure.

in sub plot-1 GA values are located in single point with in boundaries and in subplot-2 showing iterations in X-axis, function maxima in Y-axis , the difference in Y-axis is too low which is very less with compare to privious study .simulation time is 30.98sec.

CONCLUSION:-

study-4 is giving better results so for our problem study-4 is the best solution.

ERRORS:-

STEPS TAKEN TO SOLVE ERRORS:-

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.