Hi, I’m fairly new to more advanced python code but I’m trying to solve three coupled ODEs using odeint. I keep getting a message and then an output of wacky looking graphs:
Message
RuntimeWarning: overflow encountered in scalar multiply
dmdt = (0.413 * A * gamma * (rho * math.exp(-h/H)) * v**3)/HVAP
ODEintWarning: Illegal input detected (internal error). Run with full_output = 1 to get quantitative information.
x = odeint(odes,x0,t)
RuntimeWarning: overflow encountered in power
return np.power(self.base, values)
code
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import math
cd = 2
rho = 1.12e-08 # kg/m^3
A = math.pi * (5.811812)**2 # m^2
gamma = 1
HVAP = 80800000 # J/kg
theta = 45 *math.pi/180
H = 85000 # scale height (m)
# rho_atm = (rho * math.exp(-h/H))
# v_0 = 18.14297*10**5
# m_0 = 3025741
# h_0 = 140000
def odes(x,t):
v = x[0]
m = x[1]
h = x[2]
dvdt = (-1/2 * cd * (rho * math.exp(-h/H)) * v**2 * A)/m
dmdt = (0.413 * A * gamma * (rho * math.exp(-h/H)) * v**3)/HVAP
dhdt = -v*math.sin(theta)
return [dvdt, dmdt, dhdt]
x0 = [18.14297*10**5, 3025741, 140000]
# print(odes(x0,0))
t = np.linspace(0,15,1000)
x = odeint(odes,x0,t)
v = x[:,0]
m = x[:,1]
h = x[:,2]
plt.plot(t,v)
plt.show()
plt.semilogy(t,m)
plt.show()
plt.plot(t,h)
plt.show()