33 lines
822 B
Python
33 lines
822 B
Python
|
from math import sin
|
||
|
import matplotlib.pyplot as plt
|
||
|
import numpy as np
|
||
|
|
||
|
def position(t):
|
||
|
if t < 0:
|
||
|
raise ValueError("t trop petit, le hamster n'est pas encore réveillé avant 8h!")
|
||
|
elif t < 2:
|
||
|
return sin(t)
|
||
|
elif t < 3:
|
||
|
return sin(2) + (t-2)*2
|
||
|
elif t < 5:
|
||
|
return (sin(2) + 2) + sin(2*(t-3)) - (t-3)
|
||
|
elif t < 5.5:
|
||
|
return sin(2) + 2 + sin(4) - 2
|
||
|
elif t <= 8:
|
||
|
return (sin(2) + 2 + sin(4) - 2) + sin(3*(t-5.5))/(t-4)
|
||
|
else:
|
||
|
raise ValueError("t trop grand, le hamster dort après 16h!")
|
||
|
|
||
|
def graph():
|
||
|
t = np.arange(0, 8, 0.1)
|
||
|
s = np.vectorize(position)(t)
|
||
|
|
||
|
fig, ax = plt.subplots()
|
||
|
ax.plot(t, s)
|
||
|
|
||
|
ax.set(xlabel="Temps (en h)", ylabel="Position (en m)",
|
||
|
title="Position de la roue")
|
||
|
ax.grid()
|
||
|
|
||
|
return ax
|