我是matplotlib / python的新手。我想在某个时间间隔内用odeint或resolve_ivp解决一些简单的ode,例如segment [0,10],其中“初始条件”在t_0 = 5而不是t_0 =0。在我看来odeint和Solve_ivp都将初始条件作为值y_0,即y_0是指定时间数组t开头的函数值。
在积分间隔的中间条件下,我该如何求解一个ode?
答案 0 :(得分:0)
''' x = distance from the sea level in meters
R = the radius of earth in meters
g = the gravitational constant at seal level in meters/seconds^2
v = velocity in meters/s
'''
v * dv / dx = -g * R ^ 2 /(R + x)^ 2
v(30)= 20
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def model(v, x):
#constants
g = 9.80665 #gravitational force at sea level
R = 6.371e6 #radius of earth
gamma = - g*(R/(R+x))**2
dvdx = 1/v*gamma
return dvdx
#Boundary conditions
v_30 = 20 # Velocity is 20 m/s at x = 30m
#time points
x = np.linspace(30, 55) # Start at 30 and not 0
#solve ODE
v_x = odeint(model, v_30, x)
#plot results
plt.plot(x, v_x)