Week 4.1 - Genetic Algorithm
stalagmite:
1. Linspace command is used for providing intervals within given value.
2. num_cases: It runs genetic algorithm for 50 times.
3. for loop: it is created to repeat the certain set of values. In below attached program ii and j is created with respect to x and y axis.
4.input_vector(1): For each value of x an array is created called input_vector.
5.input_vector(2): For each value of y an array is created called input_vector.
6. stalagmite(input_vector): stalagmite is a functiuon which takes input vector and calculates f.
7.end : It is used to end the for loop
8. tic: It is the command used to calculate the operation time performed
9. [inputs,fopt(i)]=ga(@stalagmite,2): Where the study for ga is started and inputs and fopt is variables and stalagmite is a function code written seperately( attached below).
10. xopt(i)=inputs(1): The x value for the input is written as xpot.
11. yopt(i)=inputs(2): The y value for the input is written as ypot.
12. end: to end the for loop.
13. study_time1=toc: The command time used to calculate the operation time for study_time1
14. subplot(2,1,1): It is used to create multiple plot within a plot
15. surfc(xx,yy,-f): It is used for craetion of surface for the fuction.
16. shading interp: It is used plot the 3d graph where the grid on the surface will appear smooth.
17. hold on: It is used to stop the graph momemtarily an then to take new graph command.
18. plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r'): It is used to plot the x,y,z axis on the graph.
19. title('unbounded inputs'): It is used to give the title to the plotted graph.
20. subplot(2,1,2): It is used to create multiple plot within the plot
21. plot(fopt): It is give to plot the graph in maxima.
22. xlabel('iterations'): It is used to represent x-axis.
24. ylabel('function maximum'): It is used to represent the y axis.
25. Similarly study2_code and study3_code is written with upper and lower bounds and ga iterations.
Theory of Genetic Algorithm:

There are a large number of problems that can be solved by genetic algorithms, take a look –
Route optimization – Used in optimizing the routes. It allows you to find the shortest or fastest route between cities or areas in a very short time. It is also very useful in Smart cities, to try to reduce CO2 emissions.
Task optimization -When it comes to getting things done in the shortest time possible, optimizing them is critical. With genetic algorithms, the calculation is also fast and efficient.
Automated management of industrial equipment – It is possible to make a calculation in real-time to optimize an automated process of industrial equipment.
Learning human-guided robot behavior – Robot learning is possible with respect to a cost function. With these algorithms, learning is done faster and more efficiently.
Financial systems – An interesting application in finance is that these algorithms allow discovering investment rules that indicate when to enter and exit a market to obtain the maximum benefits. On the other hand, in Split wise methods, the method of sharing expenses between different users can be optimized.
Finding Errors in Programs – It allows you to detect errors in the programs of the developers, which helps to save time and money in their implementation.
Conclusion
We can say that genetic algorithms have proved to be very useful tools to give fast results in search and optimization problems. Although finding the exact solution to the problem is not always guaranteed, but the approximation is good enough.
Syntax for 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(_ _ _)