Description
GitHub Classroom
Lab 9 β Gradient descent
Goals and preliminaries
Installing Matplotlib
In this lab, we will plot a figure to illustrate the output of your code, this library
is very commonly used in Python to plot curves: Matplotlib You can install Matplotlib by typing the following in your terminal:
pip install matplotlib
A little story
A little story
I β The landspace
Equations of the landscape and slope
Landscape: Our terrain, is defined by the equation:
π¦ = π₯2 + 10sin(π₯).
The sleds will randomly land within +/- 10 units from the treasure’s location.
Slope’s Role & Equation: The slope at a point influences the sled’s speed and direction, with steeper slopes resulting in faster movement. The slope of our landscape at any position π₯ is given by the derivative of our landscape equation:
2π₯ + 10cos(π₯).
Your Task: Implement two Python functions in the module landspace.py:
elevation(x): Returns the elevation at position x.
slope(x): Returns the slope at position x using the derivative equation.
IMPORT IT INTO YOUR MAIN CODE!
The treasure right here
II β The sleds: attributes
Your Task: Implement the initialization function of the Sled class with the following characteristics: a name, a random initial position, and a constant speed.
III β The sleds: methods
2. found_treasure()
This method checks if the sled is close enough to the treasure’s location (the lowest point). If the sled’s position is within a certain threshold of the treasure, it has found the treasure (return True, else return False)! This threshold is set in the main at 0.05
Your Task: Implement these two methods
IV β The race
Your Task: use your method move and break the loop whenever you have a winner
Conclusion




Reviews
There are no reviews yet.