Effacer les filtres
Effacer les filtres

Genetic Algorithm with a graph

6 vues (au cours des 30 derniers jours)
Margetik
Margetik le 19 Jan 2021
Réponse apportée : Star Strider le 15 Juil 2024 à 11:14
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?

Réponses (2)

Prateekshya
Prateekshya le 15 Juil 2024 à 9:39
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.

Star Strider
Star Strider le 15 Juil 2024 à 11:14
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.
.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by