Défi : Résoudre le Problème d'Optimisation
Tâche
Swipe to start coding
Considérons un problème d'optimisation lié à la physique où nous devons trouver la hauteur maximale atteinte par un objet lancé verticalement vers le haut avec une vitesse initiale donnée.
Nous avons l'équation suivante :
h = v * t - 0.5 * g * t**2
qui décrit le mouvement d'un objet.
Notre tâche est de trouver le temps t
lorsque l'objet atteint sa hauteur maximale, puis de trouver la hauteur maximale h_max
.
- Calculez les dérivées de premier et de second ordre pour la fonction
h
. - Trouvez les points critiques de la fonction
h
. - Vérifiez si ces points critiques sont des points de maximum de la fonction
h
.
Solution
99
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
import sympy as sp
# Define the symbols
t = sp.symbols('t')
# Define the height function h(t)
v = 15.0 # Initial velocity in m/s
g = 9.81 # Acceleration due to gravity in m/s^2
h = v * t - (1/2) * g * t**2
# Calculate the first and second derivatives of h(t)
h_prime = sp.diff(h, t)
h_double_prime = sp.diff(h_prime, t)
# Find the critical points by solving h'(t) = 0
critical_points = sp.solve(h_prime, t)
# Identify the maximum height by evaluating h''(t) at each critical point
maximum_height = -1
for t_critical in critical_points:
h_double_prime_value = h_double_prime.subs({t:t_critical})
if h_double_prime_value < 0:
maximum_height = h.subs({t:t_critical})
# Print the result
if maximum_height != -1:
print(f'The object reaches its maximum height of {maximum_height:.2f} meters at time t = {t_critical:.2f} seconds.')
else:
print('There is no maximum height (object doesn\'t reach the ground).')
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 5
single
99
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
import sympy as sp
# Define the symbols
t = sp.symbols('t')
# Define the height function h(t)
v = 15.0 # Initial velocity in m/s
g = 9.81 # Acceleration due to gravity in m/s^2
h = v * t - (1/2) * g * t**2
# Calculate the first and second derivatives of h(t)
h_prime = sp.___(h, t)
h_double_prime = sp.diff(___, t)
# Find the critical points by solving h'(t) = 0
critical_points = sp.___(h_prime, t)
# Identify the maximum height by evaluating h''(t) at each critical point
maximum_height = -1
for t_critical in critical_points:
h_double_prime_value = h_double_prime.___({t:t_critical})
if h_double_prime_value < 0:
maximum_height = h.subs({t:t_critical})
# Print the result
if maximum_height != -1:
print(f'The object reaches its maximum height of {maximum_height:.2f} meters at time t = {t_critical:.2f} seconds.')
else:
print('There is no maximum height (object doesn\'t reach the ground).')
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion