【问题标题】:Plotting the basin of attraction of a Duffing oscillator with matplotlib使用 matplotlib 绘制 Duffing 振荡器的吸引力盆地
【发布时间】:2019-03-23 02:46:00
【问题描述】:

我有一个常微分方程组,它有两个吸引子,一个在 (1, 0),另一个在 (-1, 0)。我想在笛卡尔坐标中绘制一个吸引盆,其中有两种颜色,显示随着时间趋于正无穷大,每个坐标点上的一个点最终会成为哪个吸引子。但是,我不知道如何用 matplotlib 绘制这样的图。 这是我现在所做的:

from scipy.integrate import ode
import numpy as np
import matplotlib.pyplot as plt
from numpy.linalg import norm

"""
The system of ODE:
x' = y
y' = x - x**3 - gamma*y
"""

# The system of equation
def f(t, r, arg):
    return [r[1], r[0] - r[0] ** 3 - arg * r[1]]

# The Jacobian matrix
def jac(t, r, arg):
    return [[0, 1], [1 - 3 * r[0] ** 2, -arg]]

# r is the vector (x,y)
# Initial condition, length of time evolution, time step, parameter gamma
def solver(r0, t0, t1, dt, gamma):

    solution = ode(f, jac).set_integrator('dopri5')

    # Set the value of gamma
    solution.set_initial_value(r0, t0).set_f_params(gamma).set_jac_params(gamma)

    return solution


# The function to find the fixed point each starting point ends at
def find_fp(r0, t0, t1, dt, gamma):
    solution = solver(r0, t0, t1, dt, gamma)
    error = 0.01
    while solution.successful():
        if norm(np.array(solution.integrate(solution.t+dt)) - np.array([1, 0])) < error:
            return 1
        elif norm(np.array(solution.integrate(solution.t+dt)) - np.array([-1, 0])) < error:
            return -1

def fp(i, j, gamma):
    t0, t1, dt = 0, 10, 0.1
    return find_fp([i, j], t0, t1, dt, gamma)

我已经定义了几个函数。 f 是一个定义方程组的函数,jac 系统的雅可比矩阵,用作使用scipy.integrate.odedopri5 方法(Kutta-Runge 方法)求解 ODE 的参数。 find_fp函数被定义为返回相空间中一个点将结束的吸引子,返回值1表示该点将结束于(1, 0),-1为(-1 , 0)。到目前为止,这些功能似乎运行良好。但是,我不知道如何使用我对matplotlib 模块所做的事情来绘制一个吸引盆地。有什么好的想法吗?

【问题讨论】:

  • 对于您的问题:plt.plot(i,j,'.b',ms=5) 应该在坐标(i,j) 处绘制一个大蓝点。如果增加探测点的密度,请缩小标记尺寸。

标签: python numpy matplotlib scipy differential-equations


【解决方案1】:

Quick'n'dirty:选择靠近静止点的初始点并向后计算一段时间的解。绘制溶液并根据吸引子着色。

gamma = 1.2

def solution(x,y):
    return odeint(lambda u,t: -np.array(f(t,u,gamma)), [x,y], np.arange(0,15,0.01))

for i in range(-10,11):
    for j in range(-10,11):
        sol = solution(-1+i*1e-4, 0+j*1e-4);
        x,y = sol.T; plt.plot(x,y,'.b',ms=0.5);
        sol = solution(+1+i*1e-4, 0+j*1e-4);
        x,y = sol.T; plt.plot(x,y,'.r',ms=0.5);
plt.grid(); plt.show();

这给出了图像

gamma 的其他值或更长的积分间隔需要小心处理,因为三次项会导致反向时间积分中的超指数爆炸。

【讨论】:

  • lutz lehmann ,,,你能画出 3 维洛伦兹和 4 维混沌系统的引力盆吗?请回复
  • 有没有链接可以找到洛伦兹系统的吸引力盆地图?
  • @Zewo:你到底是什么意思? Lorenz 系统(具有标准参数)只有一个(奇怪的)吸引子,几乎所有解决方案都遵循靠近“蝴蝶”的曲线,围绕一个,然后是另一个鞍点(具有强烈吸引方向,和在垂直平面上缓慢向外盘旋)。
  • 我的意思是这可能只是可视化来为那些具有超过 2 个微分方程系统的系统制作吸引盆。就像 Lorenz、rosller 3D 和其他 4D 和 5D 系统一样。
猜你喜欢
  • 2016-02-20
  • 1970-01-01
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 2015-11-30
  • 2019-11-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多