%close all;
clear all;
clc;

figure;
%{
 xlim([-2.5 2]);
 ylim([-1.5 1.5]);
 
 vx=-2.5:0.05:2;
 vy=vx-vx.^3/3;
 wx=vx;
 wy=(wx+0.7)./0.8;

 subplot(2,1,1);
 hold on
 plot(vx,vy);
 plot(wx,wy);
%
 
%
 for i = 0:0.1:0.1
     x0 = [-2, -1.1+i];
     [t, phi] = ode45(@(t,x)fnode(t,x),[0 50],x0);
     subplot(2,1,1);
     plot(phi(:,1),phi(:,2),'r');
     subplot(2,1,2);
     plot(t,phi(:,1));
     hold on
     
 end
%}

%{
%% Az egyensúlyi pont körül mi történik, mmikor fog tüzelni a neuron?
figure;
 t0=[0 150];
 x0 = [-1.2, -0.625];
 
 
 for i=1:10
     nv=0.3*randn(1,2);
     x02=x0+nv;
     [t, phi] = ode45(@(t,x)fnode(t,x),t0,x02);
     subplot(2,1,1);
     plot(phi(:,1),phi(:,2),'r');
     
     subplot(2,1,2);
     plot(t,phi(:,1));
     ylim([-2.2,2.5]);
     hold on
 end
%}

%
%% Mi történik ha tologatjuk a görbét?

 figure
 xlim([-2.5 2]);
 ylim([-1.5 1.5]);
 t0=[0 150];
 
 s=1.7;
 
 vx=-2.5:0.05:2;
 vy=vx-vx.^3/3+s;
 wx=vx;
 wy=(wx+0.7)./0.8;
 
 subplot(2,1,1);
 hold on
 plot(vx,vy);
 plot(wx,wy);
 
 x02=[0.1, 1];
 [t, phi] = ode45(@(t,x)fnode3(t,x,s),t0,x02);
 subplot(2,1,1);
 plot(phi(:,1),phi(:,2),'r');
     
 subplot(2,1,2);
 plot(t,phi(:,1));
 ylim([-2.2,2.5]);
 hold on
%}

%{
%% Hiperpolarizáció utáni akciós potenciál
% negatív áram után mitörténik?
% Hirtelen lejjebb rakjuk 

figure
xlim([-2.5 2]);
ylim([-1.5 1.5]);
t0=[0 150];

s=-0.5;

vx=-2.5:0.05:2;
vy=vx-vx.^3/3+s;
wx=vx;
wy=(wx+0.7)./0.8;

vx2=-2.5:0.05:2;
vy2=vx2-vx2.^3/3;
wx2=vx2;
wy2=(wx2+0.7)./0.8;


subplot(2,1,1);
hold on
plot(vx,vy);
plot(wx,wy);

plot(vx2,vy2,'g');
plot(wx2,wy2,'g');



x02=[-1.448, -0.94];
[t, phi] = ode45(@(t,x)fnode4(t,x),t0,x02);
subplot(2,1,1);
plot(phi(:,1),phi(:,2),'r');
    
subplot(2,1,2);
plot(t,phi(:,1));
ylim([-2.2,2.5]);
hold on
%}





