是的,这是可能的。在a 是常量的情况下,我猜你叫scipy.integrate.odeint(fun, u0, t, args) 其中fun 在你的问题中被定义,u0 = [x0, y0, z0] 是初始条件,t 是要解决的时间点序列ODE 和args = (a, b, c) 是要传递给fun 的额外参数。
在a 取决于时间的情况下,您只需将a 重新考虑为一个函数,例如(给定一个常量a0):
def a(t):
return a0 * t
然后您将不得不修改 fun,它计算每个时间步的导数,以将先前的更改考虑在内:
def fun(u, t, a, b, c):
x = u[0]
y = u[1]
z = u[2]
dx_dt = a(t) * x + y * z # A change on this line: a -> a(t)
dy_dt = b * (y - z)
dz_dt = - x * y + c * y - z
return [dx_dt, dy_dt, dz_dt]
最后,请注意u0、t 和args 保持不变,您可以再次调用scipy.integrate.odeint(fun, u0, t, args)。
关于这种方法的正确性的一句话。数值积分近似的性能受到影响,我不知道具体如何(没有理论上的保证),但这是一个有效的简单示例:
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import scipy.integrate
tmax = 10.0
def a(t):
if t < tmax / 2.0:
return ((tmax / 2.0) - t) / (tmax / 2.0)
else:
return 1.0
def func(x, t, a):
return - (x - a(t))
x0 = 0.8
t = np.linspace(0.0, tmax, 1000)
args = (a,)
y = sp.integrate.odeint(func, x0, t, args)
fig = plt.figure()
ax = fig.add_subplot(111)
h1, = ax.plot(t, y)
h2, = ax.plot(t, [a(s) for s in t])
ax.legend([h1, h2], ["y", "a"])
ax.set_xlabel("t")
ax.grid()
plt.show()
我希望这会对你有所帮助。