% Plots of Dog data (2 Exponential Peeling Fits)
load 'dog'; t = dog(:,1); d = dog(:,2);
% Divide data into 3 phases (rapid, middle, terminal)
t1 = t(1:5,:);t2 = t(6:10,:);t3 = t(11:17,:);
d1 = d(1:5,:);d2 = d(6:10,:);d3 = d(11:17,:);
% log of terminal data for exponential fit
ld3=log(d(11:17,:)); LA3 = vanA(t3,1);  
aa3 = LA3\ld3;  % Least squares fit to log data
% Subtract terminal exponential from rapid and middle data
d1a = d1 - exp(aa3(1))*exp(aa3(2)*t1);
d2a = d2 - exp(aa3(1))*exp(aa3(2)*t2);
% log of modified middle data
ld2=log(d2a); LA2 = vanA(t2,1);
aa2 = LA2\ld2; % Least squares fit to log data
t4 = t(1:10,:); % Extended domain for graphing

%Plot Data and Models
tt = linspace(0,400,200);
semilogy(t1,d1,'ro'); % Rapid phase data
hold on
semilogy(t2,d2,'ro'); % Middle phase data
semilogy(t3,d3,'bo'); % Terminal phase data
% Graph best terminal phase exponential model
semilogy(t,exp(aa3(1))*exp(aa3(2)*t),'b-');
% Graph data - terminal phase model
semilogy(t1,d1a,'o','color',[0.65,0.1,0.7]);
semilogy(t2,d2a,'mo'); 
% Graph best middle phase exponential model
semilogy(t4,exp(aa2(1))*exp(aa2(2)*t4),'m-');
grid
ylim([0.07,10]);

% Set up fonts and labels for the Graph
fontlabs = 'Times New Roman';  
xlabel('$t$ (min)','FontSize',16,'FontName',fontlabs, ...
    'interpreter','latex');  
ylabel('$C$ (ng/ml)','FontSize',16,'FontName',fontlabs, ...
    'interpreter','latex'); 
mytitle = 'Plasma Concentration of Fentanyl';
title(mytitle,'FontSize',16,'FontName', ...
    'Times New Roman','interpreter','latex'); 
set(gca,'FontSize',16);

print -depsc expeel2bx_gr.eps
