1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| mport numpy as np
import matplotlib.pyplot as plt
# Constantes
g = 9.81
m = 0.2
v0 = 14
x0 = 0
y0 = 1
a = 10
rho = 1.30
ct = 0.033
cp = 0.080
# Surface de référence
A = np.pi * (0.4/2)**2
# Paramètres de temps
duree = 15
N = 1000
dt = duree / N
t = np.linspace(0, duree, N)
def solve():
ts, xs, ys = list(), list(), list()
x, y = x0, y0
vx, vy = v0, 0.0
for t in np.linspace(0, duree, N):
if t != 0.0:
# Calcul de l'accélération
ax = -0.5 * rho * A * ct * (vx**2 + vy**2) / m
ay = 0.5 * rho * A * cp * (vx**2 + vy**2) / m - g
# Integration pour la vitesse
vx += ax * dt
vy += ay * dt
# Integration pour la position
x += vx * dt
y += vy * dt
if y <= 0.0:
break
# Enregistre
ts.append(t)
xs.append(x)
ys.append(y)
return ts, xs, ys
ts, xs, ys = solve()
fig, axes = plt.subplots(2, sharex=True)
axes[0].plot(ts, xs)
axes[0].set_ylabel('X (m)')
axes[1].plot(ts, ys)
axes[1].set_ylabel('Y (m)')
for ax in axes:
ax.grid(True)
axes[-1].set_xlabel('Temps (s)')
plt.show() |
Partager