Chua-Circuit
Sat 17 May 2025
from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook
from bokeh.models import ColumnDataSource
# Set Bokeh output to notebook
output_notebook()
import numpy as np
from scipy.integrate import odeint
from bokeh.plotting import figure, show
# Chua's Circuit parameters
alpha = 15.6
beta = 28.0
# Piecewise linear function for the Chua circuit
def chua_m(x):
m0 = -1.143
m1 = -0.714
return m1 * x + 0.5 * (m0 - m1) * (np.abs(x + 1) - np.abs(x - 1))
# Chua's Circuit function
def chua_circuit(state, t):
x, y, z = state
x_dot = alpha * (y - x - chua_m(x))
y_dot = x - y + z
z_dot = -beta * y
return [x_dot, y_dot, z_dot]
# Initial conditions and time steps
initial = [0.7, 0, 0]
t = np.linspace(0, 100, 10000)
# Solve Chua's Circuit equations
solution = odeint(chua_circuit, initial, t)
x = solution[:, 0]
y = solution[:, 1]
z = solution[:, 2]
# Rotate the data for a different perspective
theta = np.pi / 4
xprime = np.cos(theta) * x - np.sin(theta) * y
# Split data into segments for multi-line
num_segments = 7
xs = np.array_split(xprime, num_segments)
ys = np.array_split(z, num_segments)
# Define a color palette
colors = ["#F0F9E8", "#BAE4BC", "#7BCCC4", "#43A2CA", "#0868AC", "#084081", "#041D54"]
# Create the Bokeh figure
p = figure(title="Chua's Circuit Visualization",
background_fill_color="#f9f9f9",
x_axis_label="X'",
y_axis_label="Z")
# Add the multi_line glyph
p.multi_line(xs, ys, line_color=colors, line_alpha=0.8, line_width=1.5)
# Show the plot
show(p)
Score: 5
Category: bokeh