# Optimization problem

Hello, i want to solve a problem using python and I don’t know how to start:
The problem is about the optimization of a runner parameter to finish a run faster.

import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt

# Définition des constantes

a = 21 # Énergie anaérobique du coureur, en J/kg
beta = 4 # Coefficient de création d’énergie en secondes carrées
T = 1.8 # Taille en mètres
m = 58 # Masse en kilos
S = (np.sqrt((T * m) / 3600)) / 2 # Surface du corps de face en fonction de la taille T et de la masse m (formule de Mosteller)
r = 1.2 # Masse volumique de l’air à 20°C
g = 9.81
pe = 20 # Pente globale en pourcentage
u = 1 # Coefficient de frottement solide estimé pour chaussure de trail
C_xS = 1 # Coefficient aérodynamique
f_air = (1 / 2) * r * C_xS

# velocity

def v(t, V, B, w):
return V + B * np.sin(w * t)

# all the forces applied on the runner and he must counter to move

def f(t V, B, w):
return g * (np.sin(np.arctan(pe / 100)) + u) + f_air * (1 / m) * (v(t, V, B, w) ** 2)

# velocity derivative

def dv_dt(t, V, B, w):
return B * w * np.cos(w * t)

# beta function represent the recreation on energy in the runner body

def beta_func(t, V, B, w):
return 4 if dv_dt(t, V, B, w) < 0 else 0

Finally I have for constraint this equation(enclosed) of energy control where e(t) represent the internal energy of the runner and is 1700 J/kg initially the rare symbol is the beta function and there is just a coefficient 1/0,25 before f*v moreover sigma is a constant called ‘a’ in my code representing the anaerobic energy.

Thus the goal is to find the best parameter V, B and w to run faster knowing we have a limited stock of energy.

What happened to the stickied post that would explain how to format code? I don’t see it in Python Help anymore.

Profile → Preferences → Interface:

1 Like

Are you able to help ?

Someone would be able to help (having enough time) if the code is formatted correctly. Could you please read the pinned thread?

1 Like

Just to make others happy, here’s the OP’s code in code fences below.
I’m on email, so I get this stuff cleanly anyway. Of course, I don’t get
images

``````import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt

# Définition des constantes
a = 21  # Énergie anaérobique du coureur, en J/kg
beta = 4  # Coefficient de création d'énergie en secondes carrées
T = 1.8  # Taille en mètres
m = 58  # Masse en kilos
S = (np.sqrt((T * m) / 3600)) / 2  # Surface du corps de face en fonction de la taille T et de la masse m (formule de Mosteller)
r = 1.2  # Masse volumique de l'air à 20°C
g = 9.81
pe = 20  # Pente globale en pourcentage
u = 1  # Coefficient de frottement solide estimé pour chaussure de trail
C_xS = 1  # Coefficient aérodynamique
f_air = (1 / 2) * r * C_xS

# velocity
def v(t, V, B, w):
return V + B * np.sin(w * t)

# all the forces applied on the runner and he must counter to move
def f(t V, B, w):
return g * (np.sin(np.arctan(pe / 100)) + u) + f_air * (1 / m) *
(v(t, V, B, w) ** 2)

# velocity derivative
def dv_dt(t, V, B, w):
return B * w * np.cos(w * t)

# beta function represent the recreation on energy in the runner body
def beta_func(t, V, B, w):
return 4 if dv_dt(t, V, B, w) < 0 else 0
``````

Thanks a lot