微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python:范德波尔方程

如何解决Python:范德波尔方程

目前,我正在尝试了解如何使用 scipy.integrate.odeint

要求解的方程是 Van Der Pol 方程

enter image description here

所以初始变量如下

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 定义为一个接受 tx函数(我认为是按照特定顺序)。我无法弄清楚如何通过将 scipy.integrate.odeint 定义为 vdp 作为第一个参数,然后 t..

来使 x 调用工作

有人可以帮我吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。