0
我不得不刚刚阅读Using adaptive step sizes with scipy.integrate.ode以及该问题的接受解决方案,甚至通过在Python解释器中复制粘贴来复制结果。在解决ODE系统时使用scipy.integrate.ode的自适应时间步骤
我的问题是,当我尝试将解决方案代码调整到自己的代码时,我只得到扁平线条。
我的代码如下:
from scipy.integrate import ode
from matplotlib.pyplot import plot, show
initials = [1,1,1,1,1]
integration_range = (0, 100)
f = lambda t,y: [1.0*y[0]*y[1], -1.0*y[0]*y[1], 1.0*y[2]*y[3] - 1.0*y[2], -1.0*y[2]*y[3], 1.0*y[2], ]
y_solutions = []
t_solutions = []
def solution_getter(t,y):
t_solutions.append(t)
y_solutions.append(y)
backend = "dopri5"
ode_solver = ode(f).set_integrator(backend)
ode_solver.set_solout(solution_getter)
ode_solver.set_initial_value(y=initials, t=0)
ode_solver.integrate(integration_range[1])
plot(t_solutions,y_solutions)
show()
非常感谢!参考资料仍然有时会让我困惑......顺便说一句,你是如何找到这个解决方案的? – Ezbob
通过调试。 q'n'd解决方案是在solution_getter内部和plot之前添加打印语句,以查看实际数据是什么。 – LutzL