Python编程:自由落体与配体 - 受体相互作用模拟
1. Python中的第一个程序:自由落体物体模拟
1.1 程序概述
下面的Python程序用于求解自由落体物体的微分方程,其与Matlab脚本有相似之处,但两种语言也存在诸多差异。
from numpy import linspace
from scipy.integrate import solve_ivp
grv_const = 9.81 # [m/s^2]
init_pos = 0.0 # [m]
init_vel = 0.5 # [m/s]
init_mass = 5.0 # [kg]
init_cond = [init_pos, init_vel, init_mass]
init_time = 0 # [s]
final_time = 5.0 # [s]
num_data = 100
tout = linspace(init_time, final_time, num_data)
def free_falling_obj(time, state, grv_const):
x1, x2, x3 = state
dxdt = [x2,
grv_const + (x3 - 2) * (x2 / x3),
-x3 + 2]
return dxdt
sol = solve_ivp(free_falling_obj, (init_time, final_time), init_cond, t_eval=tout, args=(grv_const,))
xout = s
超级会员免费看
订阅专栏 解锁全文
2442

被折叠的 条评论
为什么被折叠?



