%% Memristor based chaotic Chua's circuit simulation
%% Bharathwaj Muthusway, June 13th 2008 - July 3rd 2008
%% mbharat@cory.eecs.berkeley.edu
%% Ref:  Stephen Lynch, Dynamical Systems with Applications using MATLAB

clear;

dmemristor=inline('[y(2);(y(3)-W(y)*y(2))/33e-9;(y(2)-y(4))/(1*-10e-3);y(3)*(1/100e-9)]','t','y');

options = odeset('RelTol',1e-7,'AbsTol',1e-7);
[t,ya]=ode45(dmemristor,[0 10e-3],[0,0.1,0,0],options);

plot(ya(:,2),ya(:,4))
title('Memristor Attractor: 2D Projection, v2 vs. v1')
fsize=15;
xlabel('v1(t) (volts)','Fontsize',fsize);
ylabel('v2(t) (volts)','Fontsize',fsize);

figure
plot(ya(:,2),ya(:,3))
title('Memristor Attractor: 2D Projection, i vs. v1')
xlabel('v1(t) (volts)','Fontsize',fsize);
ylabel('i(t) (amps)','Fontsize',fsize);

figure
plot(ya(:,2),ya(:,1))
title('Memristor Attractor: 2D Projection, phi vs. v1')
xlabel('v1(t) (volts)','Fontsize',fsize);
ylabel('phi(t) (weber)','Fontsize',fsize);

figure
plot(ya(:,3),ya(:,1))
title('Memristor Attractor: 2D Projection, phi vs. i')
xlabel('i(t) (amps)','Fontsize',fsize);
ylabel('phi(t) (weber)','Fontsize',fsize);

figure
plot(t,ya(:,2))
hold
plot(t,ya(:,4),'r')
title('Memristor chaotic time series: v1 (blue) and v2 (red)')

figure
plot(t,ya(:,1))
hold
plot(t,ya(:,3),'r')
title('Memristor chaotic time series: phi (blue) and i (red)')

%% 3d plot: flux, voltage and current
figure
plot3(ya(:,1),ya(:,4),ya(:,3));
grid on
xlabel('phi(t) (webers)','Fontsize',fsize);
ylabel('v2(t) (volts)','Fontsize',fsize);
zlabel('i(t) (amps)','Fontsize',fsize);
title('Memristor 3D attractor');
