Challenge

Week 5 - Genetic Algorithm

AIM: To write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function and also plot graphs for all 3 studies and for F maximum vs no. of iterations.

OBJECTIVES:

1.Write a code for the optimise the stalagmite function.

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

3.the global maxima of the function.

PROCEDURE:

1.first i started writting the program with clear all,close all and clc to remove the all last program commands.

2. then i given the all the inputs for the optimise the stalagmite function.

fig: main program part 1.

3.then i converted the 1D array into 3D array for that i used the "meshgrid" command for x and y.

4.then i started writting the for loop for "i" here i change for 1 to the xx. then another for loop is used for j is changed from 1 to yy.

5. then i given the input (1) is given by the xx is cahnge along the i and j. then for one value of i is change all the j value .

6.then i given the input (2) is given by the xx is cahnge along the i and j. then for one value of i is change all the j value .

7. then i given the variable f(i,j) is given by the "stalagmite" then i have given the for xx and yy the change of i nad j.then i end the both the for loops.

8.then i given the surface plot to the stalagmite type of plot. the plot is having the x, y and f. before runing the progran i went to write the function code.

9. here i have given the input values are the input arregiments then i have writen the given equations in the varibles f1x, f1y,f2x and f2y. then i multplied the all f values and end the function coad.

CASE 1

1. here the case 1 is the unbounded GA study. in this sudy the i value change along the change of the num_cases in the for loop.

{for i = 1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end}
2. hera the ga(@stalagmite,2) is the solver of the ga and function name and no. of varibles. then i have given the x and y optimation values that is inputs 1 and inputs 2. then is ended the forloop.
3. then i went to the plotting the surfce plot.
fig: main program part 2
4.here th i used then the command to plot the two plots in the on plot by using the " subplot" the values inthe the is given is 2 for the two plot in one the another one is tha for the top plot.
5. then i have given the surfc plot of x,y and -f. the next command is for the shading area of the plot.
6. the plot is made by the xopt,yopt and -fopt and i given the indication of the optimizion value is by o and the color is red.
then i have given the all the x and y labels and the title and sub plot is also given plot of (-fopt) is the second subplot.
OUTPUT:
fig: unbound plot.
1. here the upper limit and the lower limites are not same.
2. then then optimum values are many in the graph.
CASE 2
1. here everything is same like the unbound study but the
{[inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0,0],[0.6,0.6]);} but here the upper and lower limits are given. the empty brucket are the vales that are not the program.
2. the plot is also same but the title name only change.
{for i = 1:num_cases
[inputs, fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0,0],[0.6,0.6]);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end}
OUTPUT:
fig: bounded ga plot.
1. here the the optimum value are few only and the limites are same.
CASE 3
1. here the bounded study with ga population in this study options varible is having the optimoptions is ga and another one having the options and the population size is given as 150.
{options= optimoptions('ga');
options =optimoptions(options,'PopulationSize',150);
tic
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}

2. the empty bracket are the values not given in the program and options and other then this every thing is same like bounded study.

OUTPUT:

fig: bounded atudy with population size

1.here the optimum value is single value this study is accurcy.

fig: all the output values.

ERRORS:

fig: function name error.

this figure is taken in the phone.

1. here the function name is different that i place in the program that is shown the error.

fig: this is the error i got due to the not mention the -ve in the plotting.

1. this error is got due to the not to mention -ve in the plotting fotp and -f in the program.

RESULT:

hence i write the program for all the case study of the bounded,unbounded and bounded with population size and global maxima is 6.1996.

CONCLUSION:

here i conclued that the bounded with the population size is the accurat function to fine the optimum value.

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.