问题描述
目前,我正在尝试了解如何使用 scipy.integrate.odeint
。
要求解的方程是 Van Der Pol 方程
所以初始变量如下
import numpy as np
import scipy.integrate
import matplotlib.pyplot as plt
t0tf = np.array([0,6.663286859323130189]) # [t0,tf]
x = np.array([2.008619860874843136,0]) # [x1,x2]
N = 25 # Number of sub intervals
T = np.linspace(t0tf[0],t0tf[1],N+1) # array with all the times
之后,我定义了以下函数
def vdp(t,x):
''' Vander Pol equation
:param t: time
:type t: int/float
:param x: state vector,[x1,x2]
:type x: np.array
:xpoint: derivative vector
'''
x1,x2 = x
return np.array([x2,(1 - x1 ** 2) * x2 - x1])
def run_vanderpol(fun,x,t):
''' To call the scipy.integrate.odeint '''
y = scipy.integrate.odeint(fun,t)
return y,t
and i call:
x0 = np.array([2.008619860874843136,0])
N = 25
t = np.linspace(0,6.663286859323130189,N+1)
print(run_vanderpol(vdp,x0,t))
这样做总是会导致错误。因此,通过进行一些研究,我发现通过像这样定义 vdp
...
def vdp(x,t): # Switched the t and x from before
''' Vander Pol equation
:param t: time
:type t: int/float
:param x: state vector,(1 - x1 ** 2) * x2 - x1])
... scipy.integrate.odeint
的调用有效并返回正确的结果(我认为)。
现在的问题是,我们被要求将 vdp
定义为一个接受 t
和 x
的函数(我认为是按照特定顺序)。我无法弄清楚如何通过将 scipy.integrate.odeint
定义为 vdp
作为第一个参数,然后 t
..
x
调用工作
有人可以帮我吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)