%%
%  Author: Peter Polcz (ppolcz@gmail.com) 
%  Created on 2023. December 07. (2023a)
%
% [2] Brahamachari and Moulick (2019). Revisiting Chua's and MLC electronic circuits: A
% MATLAB approach to solve the circuit equations. Journal of Emerging Technologies and
% Innovative Research, 6(1), 2019.
%
% Chua circuit with a chaotic attractor with double scroll.


R = 1.79e3;
C1 = 10e-9;
C2 = 100e-9;
L = 18e-3;

alpha = C2/C1;
beta = C2*R^2/L;

Ga = -0.758e-3;
Gb = -0.409e-3;

a = R*Ga;
b = R*Gb;
h = @(x) b*x + 2\(a-b)*(abs(x+1) - abs(x-1));

f = @(t,x) [
    alpha * ( x(2) - x(1) - h(x(1)) )
    x(1) - x(2) + x(3)
    -beta*x(2)
    ];

[t,x] = ode45(f,[0,1000],[1;1;1]/10);

fig = figure(2);
Tl = tiledlayout(3,2,'TileSpacing','tight','Padding','compact');

% Plot the solution in the phase diagram.
ax = nexttile([3,1]);
plot3(x(:,1),x(:,2),x(:,3))

xlabel x
ylabel y
zlabel z
grid on, box on
axis vis3d

% Plot the x1, x2, and x3 functions
ax1 = nexttile; grid on, box on, hold on
plot(t,x(:,1))

ax2 = nexttile; grid on, box on, hold on
plot(t,x(:,2))

ax3 = nexttile; grid on, box on, hold on
plot(t,x(:,3))

Link = linkprop([ax1,ax2,ax3],'XLim');
xlim([0,200])

