Skip to content

Instantly share code, notes, and snippets.

@kayhman
Last active October 2, 2020 11:40
Show Gist options
  • Save kayhman/d4dd9dcd35d91f3694a5f11aede456eb to your computer and use it in GitHub Desktop.
Save kayhman/d4dd9dcd35d91f3694a5f11aede456eb to your computer and use it in GitHub Desktop.
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