Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Défi : Résoudre le Problème d'Optimisation | Analyse Mathématique
Mathématiques pour l'Analyse de Données et la Modélisation

book
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.

  1. Calculez les dérivées de premier et de second ordre pour la fonction h.
  2. Trouvez les points critiques de la fonction h.
  3. Vérifiez si ces points critiques sont des points de maximum de la fonction h.

Solution

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 ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 5
single

single

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

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt