V_Cmin=min(x(:,1));V_Cmax=max(x(:,1));
I_Amin=min(x(:,2));I_Amax=max(x(:,2));
I_Namin=min(x(:,4));I_Namax=max(x(:,4));

V_Crange=abs(V_Cmax-V_Cmin);
I_Arange=abs(I_Amax-I_Amin);
I_Narange=abs(I_Namax-I_Namin);

%I_Amin=0;I_Amax=1.25;I_Arange=I_Amax-I_Amin;

range=max([V_Crange,I_Arange,I_Narange]);

rangeslack=.1;

lnwd=1.5;


%%%%%%%%%%%%%%%%%%%
% Plot I_Na-nullsurface
%%%%%%%%%%%%%%%%%%%

I_Amin=-.39;I_Amax=-.32;
I_Arange=abs(I_Amax-I_Amin);
[a,b]=meshgrid(0:.04:1, 0:.04:1);
c1=0.*a+0;c2=0.*a+0.25;c3=0.*a+0.6;

clear V_C I_A I_Na 

I_A=I_Amin+a*(I_Amax-I_Amin);
I_Na=I_Namin-rangeslack*I_Narange+b*(I_Namax+2*rangeslack*I_Narange-I_Namin);
V_C= Na(I_Na)+E_Na;

mesh(I_A,V_C,I_Na,c2);


hold on;

axis([-.39 -.32 -.6 1.5 -.2 0.55])


%%%%%%%%%%%%%%%%%%%
%%% Intersection of V_C-nullsurface with I_Na-nullsurface
%%%%%%%%%%%%%%%%%%%
clear V_C I_A I_Na 
%I_Namin=-.4;I_Namax=1.4
I_Namin=-.1405;
I_Namax=-.005;
I_Na=I_Namin:(I_Namax-I_Namin)/30:I_Namax;
V_C= Na(I_Na)+E_Na;
I_A =-(I_Na+K(V_C-E_K)+Cl(V_C-E_Cl)-Iin);
plot3(I_A,V_C,I_Na+.005,'b-','linewidth',lnwd);


%%%%%%%%%%%%%%%%%%%
%%% Intersection of I_A-nullsurface with I_Na-nullsurface
%%%%%%%%%%%%%%%%%%%
clear V_C I_A I_Na 
%I_A = (I_Amin-2*rangeslack*I_Arange):0.1*I_Arange:(I_Amax+2*rangeslack*I_Arange);
I_Amax=-.3;I_A =(1.03*I_Amin):(I_Amax-I_Amin)/5:I_Amax; 
V_C=R*I_A;
I_Na=(V_C-E_Na)/r1;
plot3(I_A,V_C,I_Na,'k--','linewidth',lnwd);

%%% Orbit %%%
plot3(x(N:end,2),x(N:end,1),x(N:end,4),'r-')


legend('{I_{Na}}^\prime = 0','{V_C}^\prime = 0','{I_A}^\prime = {I_S}^\prime =0','Orbit')
xlabel('I_A','fontsize',16)
ylabel('V_C','fontsize',16)
zlabel('I_{Na}','fontsize',16)


%%%%%%%%%%%%%%%%%%%
% Drop-off, and Touch-up Line
%%%%%%%%%%%%%%%%%%%
clear V_C I_A I_Na cl
I_A = (I_Amin):(I_Amax-I_Amin)/20:(I_Amax);
V_C = Na(i2)+E_Na;
I_Na = (V_C-E_Na)/r1;
%figure(1)
plot3(I_A,V_C+0*I_A,I_Na+0*I_A+.005,'m.', 'linewidth',lnwd);
clear V_C I_Na
V_C = Na(i1)+E_Na;
I_Na = (V_C-E_Na-(-r1+r2)*(i2-i1))/r1;
plot3(I_A,V_C+0*I_A,I_Na+0*I_A+.005,'m.', 'linewidth',lnwd);


