%{  
    Filename:       ShewieTime.m      
    Author:         Dylan Webster         
    Created:        7 October 2012    
    Modified:       7 October 2012   
    Relevant to:    Predicts transient behavior of the SAFE BET with an 
                    oscillating analyte input modelled by a sine wave.
                    Assumes characteristic time response on the order of
                    1.5 days, as estimated from initial characterization 
                    experiments with sodium arsenite.
%}
%%
function [t,i] = ShewieTime()    

D = 3.6; % [/day]
A0 = 300; % [uM]
T = 10; % [days]
f = 1/T; % [1/day]
t = .1:.1:10;
c = ((A0*(D^2*sin(2*pi*f.*t)+D^2-2*pi*D*f*cos(2*pi*f.*t)+4*pi^2*f^2))/(D^2+4*pi^2*f^2));

t_max = 10; % [days]
[T,i] = ode45(@F1,[0 t_max], 0);
plotyy(T,i,t,c)
%plot(T,i)

end
%%
function di = F1(t,i)

D = 3.6; % [/day]
A0 = 300; % [uM]
T = 10; % [days]
f = 1/T; % [1/day]
Bmax = 1.3862; % [uA/day]
B0 = 2.774; % [uA/day]
cc = 100; % [uM]
a = 0.6931; % [/day]


di = (Bmax*((A0*(D^2*sin(2*pi*f*t)+D^2-2*pi*D*f*cos(2*pi*f*t)+4*pi^2*f^2))/(D^2+4*pi^2*f^2)))/(cc+((A0*(D^2*sin(2*pi*f*t)+D^2-2*pi*D*f*cos(2*pi*f*t)+4*pi^2*f^2))/(D^2+4*pi^2*f^2)))+B0-a*i;
end