# MATLAB TUTORIAL. Part 2.3: Chua Circuits

Chua Circuits

Many physical devices are modeled in such a way that the equations defining the system have $$\mathbb{Z}_2$$-symmetry (invariance under the change of the sign in the state variables). In these systems, the origin is always an equilibrium point.

The Chua's equation is a model of one of the simplest electronic circuits, exhibiting a wide range of complex dynamical behaviors. Let us consider the Chua's equation with a cubic nonlinearity (see [Pivka et al., 1996]):

$\begin{split} \dot{x} &= \alpha \left( y - a\,x^3 -c\,x \right) , \\ \dot{y} &= x-y+z , \\ \dot{z} &= - \beta \, y - \gamma \, z . \end{split}$
In this equation a parameter γ is included in order to take into account small resistive e ects in the inductance. function circuit
% Data for Chua's oscillator
% ___________________________________________________________
nc = 3;     % number of contours: 1, 2, 3, 4.
rv = 1;     % ordinal number(s) of vert edge(s) (resistor)
rh = [1,2]; % index(es) of horz edge(s): row, col
cv = [2,3]; % ordinal number(s) of vert edge(s) (capacitor)
ch = 0;     % index(es) of horz edge(s): row, col
iv = 1;     % ordinal number(s) of vert edge(s) (inductor)
ih = 0;     % index(es) of horz edge(s): row, col
uv = 4;     % ordinal number(s) of vert edge(s) (Chua)
% ___________________________________________________________
% For universal Chua's circuit delete percentage sign below:
% iv = 0; ih = [1,2];

ar = 1.75;  % aspect ratio, horz./vert.
% aspect ratio dependent coefficients:
cm =  ar/20;
cm1 = ar/100;
k = ar/40;
s2 = ar/10;
sh = cm1*nc;
ws =.3*ar/1.8;

x = (0:7)'*cm1; % resistor
y = [0; 1.1; - 1.1; 1.1; - 1.1; 1.1; - 1.1; 0]*ar*cm1;

z = -.8572:0.0002:0.5717;  % inductor
t = (z+1)*pi*3.5;
v = 2*cos(t)'*cm1;
u = ((z + 0.35*(-sin(t) + 1))/17 + .75)';

ux = [-2.75; -2.75; 8; 8; -2.75]*cm1; % Chua's device
uy = [-1.45; 1.45; 1.45; -1.45; -1.45]*ar*cm1;
ux1=ux/5 - max(uy) + max(y);

ca = [.5,0; .5,1; 1,1; 1,0]; % capacitor

d(nc+1)=0; % memory allocation
for j = 1:nc + 1
d(j) = ar/nc*(j-1);
end

q = '123456789'; % indices
fz = 'fontsize'; % property name
fs = 13; % property value

b = [0,1; 1,0]; % rotation

contr(nc,ar) % drawing contours

for j = cv(cv>0) % capacitors on vertical edges
s = [4, - .5 + d(j)/cm];
s1 = s(1)*cm;
c = (ca + s)*cm; % capacitor
mm = max(c(3:4,:) - c(1:2,:));
w = [d(j),mm(1); d(j),mm(2)] + [s1,0;s1,0]*b;
cr(1,w,c*b,0,0)
text(d(j) - .17, c(2,1) + .025,['C_',q(j)],fz,fs)
end

for j = 1:2:numel(ch)*all(ch) % capacitors on horizontal edges
aa = ar /nc*(ch(j + 1) - 1);
ac = cm/nc*(j - 1);
s = [4 + aa/cm, - .5];
s1 = s(1)*cm - ac;
c = ([.5,0; .5,1; 1,1; 1,0] + s)*cm; % capacitor
mm = max(c(3:4,:) - c(1:2,:)) + ac;
w = [0,mm(1); 0,mm(2)]*b + [s1,0; s1,0];
cr(1,w,c,2 - ch(j),sh)
text(c(1,1) - .1, c(1,2) + 2.16 - ch(j),...
['C_',q(ch(j)),'_,_',q(ch(j+1))],fz,fs)
end

uu=[rv,uv];
for j = uu(uu>0) % resistors on vertical edges
w = [s2,d(j); s2 + max(x),d(j)]*b;
c = [x,y]*b + [d(j),s2]; % resistor
cr(0,w,c,0,0)
if j <= numel(rv)
text(c(1,1) - .16, c(1,2) + .075,['R_',q(j)],fz,fs)
end
end

for j = 1:2:numel(rh)*all(rh) % resistors on horizontal edges
aa = ar/nc*(rh(j + 1) - 1);
w = [s2 + aa,0; s2 + max(x) + aa,0];
c = [x,y] + [0,s2 + aa]*b; % resistor
cr(0,w,c,2 - rh(j),sh)
text(c(1,1) - .1, c(1,2) + 2.125 - rh(j),...
['R_',q(rh(j)),'_,_',q(rh(j+1))],fz,fs)
end

for j = iv(iv>0) % inductors on vertical edges
w = [.6996,d(j); .789 + max(v),d(j)]*b;
c = [v,u] + [d(j),0]; % inductor
cr(0,w,c,0,0)
text(c(1,1) - .16, c(1,2) + .075,['L_',q(j)],fz,fs)
end

for j = 1:2:numel(ih)*all(ih) % inductors on horizontal edges
aa = ar/nc*(ih(j + 1) - 1);
w = [s2 + aa + ws, 0; s2 + range(u) + aa + ws, 0];
c = [(u - min(u))*max(x)/range(u)*1.8/ar ...
+ ws, -v] + [0, s2 + aa]*b;  % inductor
cr(0,w,c,2 - ih(j),sh)
text(c(1,1) - .05, c(1,2 ) + 2.125 - ih(j),...
['L_',[q(ih(j)),'_,_',q(ih(j+1))]],fz,fs)
end

for j = uv(uv>0) % Chua device on vertical edges
c = [ux,uy]*b + [d(j),s2];
c1 = [ux1,uy]*b + [d(j),0.14];
k1 = c(2,1) + k;
text([k1, k1, k1], [c(1,2) - k, c(2,2) + 5*k, c(2,2) + 2*k]...
,{'+','-','N_R'},fz,fs)
plot(c(:,1),c(:,2),'b')
fill(c1(:,1),c1(:,2),'b')
end

set(gcf,'color','w')
axis off
hold off
end

function cr(f,w,c,vh,sh)
plot(w(:,1) - sh,w(:,2) + vh,'w')
switch f
case 0
plot(c(:,1) - sh,c(:,2) + vh,'b')
case 1
plot(c(1:2,1) - sh,c(1:2,2) + vh,'b',...
c(3:4,1) - sh,c(3:4,2) + vh,'b')
end
end

function contr(nc,sz)
yr = [0,0,1,1,0]; % contour (rectangle)
xr = [0,sz,sz,0,0];
plot(xr,yr,'b');
axis([ -.1*sz, sz*1.05,  -.1*sz, 1.1], 'equal');
hold on
for i = 2:nc % internal vertical edges
plot([sz,sz]/nc*(i - 1),[0,1],'b.-','markersize',12);
end
end



disp("Non-linear Differential Equations");
disp("Chua's Circuit")
disp('Background:')
disp("Chua's circuit was invented by Leon Chua in 1983.")
disp('The circuit is an autonomous nonperiodic oscillator that must contain a locallly active resistor')
disp('which is a device that has a negative resistance which amplifies current')
disp('3 differential equations:')
disp('(dx/dt)= a[y-x-g(x)]')
disp('(dy/dt)= x-y+z')
disp('(dz/dt)= -By')

%solving the 3 differential equtions and graphing the results
% the initial x position is 1 while y and z are 0
% graphs for t from 0 to 150 seconds
% the ode45 command is used to solve differential equations
[t,y] = ode45(@chua_function,[0 150],[1 0 0]);
%the solution is graphed
plot3(y(:,1),y(:,2),y(:,3),'r')
title("Chua's circuit")
xlabel('Capasitor 1 voltage')
ylabel('Capasitor 2 voltage')
zlabel('Curent in the inductor')
grid

function out = chua_function(~,p)
% t represents time and p represents position
a = 16; % 'a' represents alpha
B = 30; % 'B' represents beta
m = -1.2; % m and n are slopes
n = -0.7;

% these values are parameters set in the main script. x is 1 and y and z are 0
x = p(1);
y = p(2);
z = p(3);

g = n*x+0.5*(m-n)*(abs(x+1)-abs(x-1));
% these equations are derivatives with respect to time of x, y, and z
xdot = a*(y-x-g);
ydot = x - y+ z;
zdot = -B*y;
% these are the values that will be graphed
out = [xdot ydot zdot]';
end