Feat: début du chapitre sur le nombre dérivé et la tangente
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
32
1ST/03_Nombre_derive_et_tangente/hamster.py
Normal file
32
1ST/03_Nombre_derive_et_tangente/hamster.py
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
Reference in New Issue
Block a user