【问题标题】:Adjusting scipy.integrate.ode to error tolerances将 scipy.integrate.ode 调整为容错
【发布时间】:2018-10-07 11:37:22
【问题描述】:

我刚刚阅读了Using adaptive time step for scipy.integrate.ode when solving ODE systems

我下面的代码运行良好,但它在求解更复杂的方程而不是我在下面的示例中提供的方程时产生的结果,微分方程似乎不准确。有没有办法更改此代码,以便它根据指定的绝对值自动调整时间步长和 相对误差容限?例如。 10^-8?

from scipy.integrate import ode

initials = [0.5,0.2] 
integration_range = (0, 30)

def f(t,X):
    x,y = X[0],X[1]

    dxdt = x**2 + y
    dydt = y**2 + x
    return [dxdt,dydt]

X_solutions = []
t_solutions = []
def solution_getter(t,X): 
   t_solutions.append(t)
   X_solutions.append(X.copy()) 


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])

【问题讨论】:

    标签: python scipy ode


    【解决方案1】:

    您可以在set_integrator 调用中设置rtolatol 的值,请参阅https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html

    默认值提供中等精度,足以用于图形,但可能不足以用于其他用途。

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 2014-11-06
      • 2011-09-06
      相关资源
      最近更新 更多