Whichever function and algorithm you chose, you might end up with a turtle in your bag. If you don’t set the limits in the simulated annealing, you might end up with a turtle off the edge of the screen.
With the slightly slanting bag, and a sensible step size, around 0.1, your turtle can settle down in the bottom of the bag as shown in the figure.
He’s settled on the far right corner of the bag. If you make a larger step size, for example, the whole width of the bag, the turtle will get stuck quickly. You see this clearly when you try a different function, such as
|||f = lambda x: math.fabs(x)|
This gives you a v-shape. ...