【发布时间】:2017-02-09 01:36:14
【问题描述】:
我必须阅读Using adaptive step sizes with scipy.integrate.ode 和该问题的公认解决方案,甚至在我的 Python 解释器中通过复制和粘贴复制结果。
我的问题是,当我尝试将解决方案代码调整为我自己的代码时,我只能得到平线。
我的代码如下:
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()
【问题讨论】:
标签: python python-3.x scipy ode