Genetic Algorithm with a graph
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function C = Myfunm(x)
C = - (14.9*100)/(x(1)^2-11.9723*x(1)+70.0051+10*cos((pi*x(1))/2)+8*sin(5*pi*x(1))-(exp(-((x(2)-0.5)^2)/2))/sqrt(5));
I solved this problem with the Genetic Algorithm and i want to present the graph which depicts the max solution depending on the number of generations. I don't know how to plot the graph. Is there a certain tool or do i have to write a new code?
0 commentaires
Réponses (2)
Prateekshya
le 15 Juil 2024
Hi Margetik,
As per my understanding, you want to plot a graph where the X-axis and Y-axis will show the number of generations and the solution.
You can use the "plot()" function to plot a graph for the above requirement. You need to create two separate lists for the number of generations and solutions. Please refer to the below example:
xData = [100 200 300];
yData = [232 2435 123];
plot(xData, yData);
In place of the numerical values you can store the number of generations in "xData" and the solution in "yData". You may also exchange the data as per the requirement.
Please refer to this link for more information on the "plot()" function: https://www.mathworks.com/help/matlab/ref/plot.html
I hope this helps!
Thank you.
0 commentaires
Star Strider
le 15 Juil 2024
I am not certaiin what you want, however creating an options structure using optimoptions and including the name-value pair 'PlotFcn',@gaplotbestf may do what you want.
The full code for that would be something like this —
opts = optimoptions('ga', 'PlotFcn',@gaplotbestf);
(add other optimoptions name-value pairs if you want more of them, and change the 'PlotFcn' plot function if my suggestion is not what you want) then include the ‘opts’ variable (or whatever you want to name it) as the last argument in your call to ga.
.
0 commentaires
Voir également
Catégories
En savoir plus sur Genetic Algorithm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!