松脆的奥丁停下来

2024-03-29 08:24:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一些模拟时,确实在scipy.integrate.odeint中观察到一个意外的行为。在

我可以用这个代码重现我的问题:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint

tau = 0.01

a, b = 0.7, 0.8

def E_p(t):
    E = -0.07
    if t < b and t > a:
        E = -0.05
    return E

def dynamics(V, t):
    return (E_p(t) - V)/tau

time = np.arange(0, 1, 0.001)
ps = odeint(dynamics, -0.07, time)

plt.plot(time, ps)

当我把a和b设置为靠近左边的间隔(在我的例子中是零)时,odeint工作得很好,而右边的间隔不是什么。在

我希望看到这个

integration

但右边更多。我真正想做的是模拟RC电路中的方脉冲。在

{2}当我发现这个函数没有收敛的时候,我觉得它不能停止。在


Tags: 代码import间隔returntimedefasnp
1条回答
网友
1楼 · 发布于 2024-03-29 08:24:05

尽管不连续性打破了大多数ODE解算器所基于的假设,但是odeint通常在处理一个不连续性方面做得很好。这里的问题很可能是由解算器使用的自适应步长引起的。在这种情况下,步长可能足够大,以至于解算器跳过它从未“看到”的脉冲。在

尝试使用odeinthmax参数。将其设置为小于脉冲宽度的值。这将确保odeint至少命中一次脉冲。自适应解算器应能合理地解决脉冲的边界问题。例如,这是有效的:

ps = odeint(dynamics, -0.07, time, hmax=0.2*(b-a))

相关问题 更多 >