% LEP 10-1 : Nonlinear regression analysis to determine model parameters
%

PT=[1;1;1;1;1;1;1;1;1;0.5;1;5;10;15;20;1];%Independent variable
PH2=[1; 1; 1; 1 ;1 ;1; 1; 2; 4; 1; 1; 1; 1; 1; 1; 1];%Independent variable
PB=[0;0;1;4;1;5;0;0;0;0;0;0;0;0;0;1];%Independent variable
RATE=[71.0197; 71.0197; 42.21931; 19.04705; 42.21931; 16.10129; 71.0197; 142.0394; 284.0788; 47.64574; 71.0197; 116.8977; 127.1662; 131.002; 133.088; 42.21931];%Dependent variable
yo=[100;1;1];%Initial guess vector for k,KB and KT
X=[PT PH2 PB];
yfinal= nlinfit(X,RATE,@ODEfun,yo);
k=yfinal(1);
KB=yfinal(2);
KT=yfinal(3);
disp('The regression parameters k, KB and KT are')
k
KB
KT
X=linspace(0,1,100);
KT=1.038;
KB=1.39;
PT0=1;
tiledlayout(2,3)
set (gcf,'Position',[0,0.1,800,400])
for i=1:100
a(i)=KT*(1-X(i))/(KB*X(i));
b(i)=1/(KB*PT0*X(i));
c(i)=KT*PT0*(1-X(i));
d(i)=(KT*PT0*(1-X(i)))/(1+KT*PT0*(1-X(i))+KB*PT0*X(i));
e(i)=1/(1+KT*PT0*(1-X(i)+KB*PT0*X(i)));
f(i)=KB*PT0*X(i)/(1+KT*PT0*(1-X(i)+KB*PT0*X(i)));
end
nexttile
plot(X(1:100),a(1:100),'LineWidth',1.5)
xlabel('X')
ylabel('C_{T.S}/C_{B.S}')
axis([0 1 0 30])
grid on
nexttile
plot(X(1:100),b(1:100),'LineWidth',1.5)
xlabel('X')
ylabel('C_{v}/C_{B.S}')
axis([0 1 0 30])
grid on
nexttile
plot(X(1:100),c(1:100),'LineWidth',1.5)
xlabel('X')
ylabel('C_{T.S}/C_{v}')
axis([0 1 0 10])
grid on
nexttile
plot(X(1:100),d(1:100),'LineWidth',1.5)
xlabel('X')
ylabel('C_{T.S}/C_{t}')
axis([0 1 0 1])
grid on
nexttile
plot(X,e,'LineWidth',1.5)
xlabel('X')
ylabel('C_{v}/C_{t}')
axis([0 1 0 1])
grid on
nexttile
plot(X,f,'LineWidth',1.5)
xlabel('X')
ylabel('C_{B.S}/C_{t}')
axis([0 1 0 1])
grid on

%

function RATE = ODEfun(yo,X)
k=yo(1);
KB=yo(2);
KT=yo(3);
RATE=k.*X(:,1).*X(:,2)./(1+KB.*X(:,3)+KT.*X(:,1));
end