Python solve_ivp [scipy.integrate]:如何设置你的积分过程的输出点数?

问题描述

我想对具有不同初始条件的相同微分方程进行积分,并且我想比较我获得的每个点。不幸的是,如果我这样做:

sol = solve_ivp(my_model,[0,leng],[1,1,1],method="LSODA",args=(rho,sigma,beta),dense_output=False)

sol_2 = solve_ivp(my_model,[1+0.001,1+0.001,1-0.001],dense_output=False)

这两个积分过程得到的点数不同

我不想使用插值过程,因为我想使用真实数据

我可以设置解的点数吗?

解决方法

比较初始条件不同的实例的一种变体是将它们全部整理成一个大系统,在该系统中它们都以相同的步骤顺序同时求解

def multi_Lorenz(t,u):
    return np.concatenate([Lorenz(t,uu) for uu in u.reshape([-1,3])])

u0 = np.concatenate([[1+k*1e-5,1+k*1e-5,1-k*1e-5] for k in range(11)])
res = solve_ivp(multi_Lorenz,[1,25],u0,method="LSODA")

plt.figure(figsize=(14,6))
plt.plot(res.t,res.y[::3].T)
plt.grid(); plt.show()

plot of the solutions

解决方案族的可见分裂位于 t=22,但是在与作为参考的 k=0 图的差异中,初始差异的十倍增加几乎立即发生在 t=1 附近的尖峰中{1}} 并保持在该范围内直到 t=12

N = max(k for k,t in enumerate(res.t) if t<12)
plt.figure(figsize=(14,6))
plt.plot(res.t[:N],(res.y[3::3,:N]-res.y[0,:N]).T)
plt.grid(); plt.show()

enter image description here