Skip to content

Instantly share code, notes, and snippets.

Last active October 2, 2020 11:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment