- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这组微分方程:
dy/dt = a*y - b*x*y
dx/dt = b*x*y - c*y(t - t_0)
t_0
是一个常数时间,当 t<t_0
时,该项被忽略。 。给定初始条件和所有系数,如何使用 numpy/scipy 在 python 中解决这个问题?
编辑:y(t-t_0)
值为 y
当时t-t_0
,不是y
次t-t_0
最佳答案
似乎对全局变量 sol_y
执行插值也有效:
import numpy as np
from scipy.integrate import ode
import matplotlib.pyplot as plt
def dudt(t, u, params):
x, y = u
a, b, c, t0 = params
dydt = a*y - b*x*y
if t <= t0:
dxdt = b*x*y
else:
dxdt = b*x*y - c*get_old_y(t-t0)
return [dxdt, dydt]
def get_old_y(old_t):
return np.interp(old_t, sol_t, sol_y)
def jac_dudt(t, u, params):
x, y = u
a, b, c, t0 = params
jac = [[ b*y, b*x-c],
[-b*y, a-b*y]]
return jac
# parameters
t0 = 1
params = 1, 1, 2, t0
u0 = [1, 2]
t_end = 3*t0
dt = 0.05
# integration
r = ode(dudt, jac_dudt).set_integrator("vode",
method="adams",
with_jacobian=True)
r.set_initial_value(u0, 0).set_f_params(params).set_jac_params(params)
sol_t, sol_x, sol_y = [], [], []
while r.successful() and r.t < t_end:
r.integrate(r.t + dt)
sol_x.append(r.y[0])
sol_y.append(r.y[1])
sol_t.append(r.t)
# graph
plt.plot(sol_t, sol_x, '-|', label='x(t)')
plt.plot(sol_t, sol_y, '-|', label='y(t)')
plt.legend(); plt.xlabel('time'); plt.ylabel('solution');
带有示例参数的输出图为:
关于python - 求解前一时间步的 ODE 函数(延迟微分方程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52243443/
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
Julia的新手,试图测试ODE求解器的速度。我在本教程中使用了Lorenz方程 using DifferentialEquations using Plots function lorenz(t,u
我来这里是因为我一直在尝试使用 sympy 求解微分方程,不幸的是到目前为止我还没有成功。到目前为止我所做的是: 1)插入微分方程,赋值并求解: import sympy as sp from IPy
我不知道问这个地方是否合适,因为我的问题是关于如何使用微分方程增长和衰减方法计算计算机科学算法的复杂性。 我想证明的算法是二分查找排序数组,其复杂度为log2(n) 算法说:如果要搜索的目标值等于中间
我想知道是否有人可以帮助我使用 MatLab 求解 Lotka-Volterra 方程。我的代码似乎不起作用。我执行以下操作: 第 1 步 - 我创建了一个名为 pred_prey_odes.m 的文
我是一名优秀的程序员,十分优秀!