Starting from:

$29.99

CSE101 Lab 9 – Gradient descent Goals and preliminaries Solution

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


More products