This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
trip_distance = 6.0 # km | |
trip_duration = 12.0 # minutes | |
trip_avg_speed = 30.0 # km/h | |
# trip duration in minutes | |
def duration(distance, speed): | |
return distance * 1/speed * 60.0 | |
real_duration = duration(trip_distance, trip_avg_speed) | |
speeds = np.linspace(5, 50) | |
duration = np.vectorize(lambda speed: duration(trip_distance, speed))(speeds) | |
error = 12 - duration | |
fig, ax = plt.subplots() | |
ax.grid(True, which='both') | |
ax.plot(speeds, duration, label='Trip duration wrt speed') | |
ax.plot(speeds, error, label='Error wrt to speed param') | |
ax.scatter([trip_avg_speed], [0], label='Error for real average speed') | |
plt.xlabel('average speed') | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment