%this function uses Euler's method to for the toggle system
function [u,v,t] = Toggle(tmax,N,alpha1,alpha2,beta,lam,k,u0,v0)
%Initially when runnning this m-file you would want to enter
%Toggle(7,700,156.25,15.6,2.5,1,1,.1,.1);
%For 2b) you would use
%Toggle(7,700,156.25,15.6,2.5,1,2.15672*10^(-10),.1,.1);
%This will insure that correct values for 
%the parameters tmax,N,alpha1,alpha2,beta,lam,k,u0,v0 are passed to the 
%m-file
dt = tmax/N; %this determines the size of the time step delta t
u = zeros(1,N+1); %define an empty vector for u(t)
v = zeros(1,N+1); %define an empty vectorr for v(t)
u(1) = u0; %first value in u vector is the inital cond.
v(1) = v0; %first value in vs vector is the inital cond.
for n = 1:N %this is the iterative loop for Euler's Method
    %if dt*n > 2
    %    k = 1;
    %end
    u(n+1) = u(n) + ((alpha1/(1 + (v(n))^beta)) - u(n))*dt;%D.E. for u(t)
    v(n+1) = v(n) + ((alpha2/(1 + k*(u(n))^lam)) - v(n))*dt;%D.E. for v(t)
end %end the for loop
t = linspace(0,tmax,N+1); %this is used only for the plotting
h1 = figure;%provide a handle for first figure 
h2 = figure;%provide a handle for second figure
h3 = figure;
figure(h1);
plot(t,u,'g')
ylabel('u(t)'), xlabel('Time'), title('First Repressor Gene')

figure(h2);
plot(t,v)
ylabel('v(t)'), xlabel('Time'), title('Second Repressor Gene')

figure(h3);
plot(t,u,'g')
hold on
plot(t,v)
title('Plot of u(t) and v(t)')
ylabel('Concentration'), xlabel('Time')
legend('u(t)','v(t)')


