How to plot a straight line graph that ends up with a plateau using simple hill climber method
5 views (last 30 days)
Show older comments
Hello! I'm stuck at trying to plot a graph based on a simple hill climbing method. i understand the algorithm correctly but idk how to start. as of now i'm working on trying to select a value (for the current best solution) using a random generator and then evaluate it if it's equal to 10 (goal state). if it's 10 then quit, if it isnt then select that as the best current solution.
Secondly from there take a new number and evaluate if it's equal to 10. (correct me if i'm wrong) and then if it's not equal to 10 compare it with the best current solution and see which is better. If the new number is of greater value than the current best solution then replace it with the new number as the current best solution and continue from there.
This is what I understand from the whole algorithm. Do correct me if otherwise.
The goal state is 10. The numbers i'm setting at the Y axis would be a vector of 10 integers starting from 0 to 10 and as for the x axis it will be an iteration number from 0 to 12 with 2 as the interval value.
0 Comments
Answers (1)
KSSV
on 8 Apr 2020
You have to proceed something like this:
sol = 0:10 ;
val0 = randsample(sol,1) ;
iter = 1 ;
y = zeros([],1) ;
x = zeros([],1) ;
x(1) = iter ;
y(iter) = val0 ;
while val0 ~= 10
val = randsample(sol,1) ;
if val > val0
val0 = val ;
iter = iter+1 ;
iter
x(iter) = iter ;
y(iter) = val0 ;
end
end
plot(x,y)
0 Comments
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!