Genetic Algorithm with a graph

6 次查看(过去 30 天)
Margetik
Margetik 2021-1-19
回答: Star Strider 2024-7-15,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?

回答(2 个)

Prateekshya
Prateekshya 2024-7-15,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 2024-7-15,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.
.

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by