首页 > 解决方案 > Chua的电路使用python和绘图

问题描述

我尝试使用 Python 实现 Chua 系统。但是图表与我们需要的非常不同。用这样的系统实现

在此处输入图像描述

我在互联网上没有找到任何地方并尝试自己做。但是在python中我仍然没有什么经验。

我得到什么: 我收到的

我需要的: 我需要的

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

a,b,e,x2=2.8,3,0.03,9
def f(y, t):
 y1, y2, y3 = y
 return [(-a/b)*(y2-y1),
 (-1/b)*((y2-y1)+y3)+(e/b)*(x2-y2),
         (b*y2)]

t = np.linspace(0,20,2001)
y0 = [1, -1, 10]
[y1,y2,y3]=odeint(f, y0, t, full_output=False).T
fig = plt.figure(facecolor='white') 
ax=Axes3D(fig)
ax.plot(y1,y2,y3,linewidth=2)
plt.xlabel('y1')
plt.ylabel('y2')
plt.title("primary: y0 = [1, -1, 10]")
y0 = [1.0001, -1, 10]
[y1,y2,y3]=odeint(f, y0, t, full_output=False).T
fig = plt.figure(facecolor='white') 
ax=Axes3D(fig)
ax.plot(y1,y2,y3,linewidth=2)
plt.xlabel('y1')
plt.ylabel('y2')
plt.title("primary: y0 = [1.0001, -1, 10]")
plt.show()

标签: pythonpython-3.xnumpygraphics

解决方案


由于我不太了解 Chua 的振荡器,除非我弄错了,否则我确实认为您的 ODE 系统定义中存在错误。

简单地基于蔡氏电路的维基百科英文页面。您似乎未能提供f描述非线性电阻器电响应的函数表达式。所以,从给定的方程和表达式开始f,这是我的尝试odeint

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# parameters
alpha = 15.395
beta = 28
R = -1.143
C_2 = -0.714

def chua(u, t):
    x, y, z = u  
    # electrical response of the nonlinear resistor
    f_x = C_2*x + 0.5*(R-C_2)*(abs(x+1)-abs(x-1))
    dudt = [alpha*(y-x-f_x), x - y + z, -beta * y]
    return dudt

# time discretization
t_0 = 0
dt = 1e-3
t_final = 300
t = np.arange(t_0, t_final, dt)

# initial conditions
u0 = [0.1,0,0]
# integrate ode system
sol = odeint(chua, u0, t)

# 3d-plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

ax.plot(sol[:,0],sol[:,1],sol[:,2])

这给出了 3d 中预期的混乱行为:

chaotic_chua

这个在 xy 平面上的美好时光演变:

chua_gif

希望这有助于使用您自己的参数集解决您的问题。


推荐阅读