T is not defined, dont know how to fix

8 views (last 30 days)
Lori
Lori on 16 Aug 2022
Commented: Star Strider on 16 Aug 2022
%functions
function dndt = lacO(t,n)
dn1=1.66*5*(2500+n(3).^2+0.1*(2500*5*2+2/80*n(3).^2))./(2500+n(3).^2+2/80*n(3).^2+500*(5+5*100)*2)-0.756*n(1); %dn1: mRNA concentration (molec)
dn2 =5*n(1) - 0.756*n(2); %dn2: enzyme concentration (molec)
dn3 =0.23*(50-2*n(3)); %dn3: intracellular IPTG concentration (molec)
dndt = [dn1; dn2; dn3];
return
%ODEs
n0=[0 0 0]; % Initial conditions
options = odeset('RelTol',1e-6,'Stats','off','Abstol',1e-6); % ODE Options
[t,n]=@ode23t(@lacO,[0 50],n0,options);
function dndt = lacO_I_c(t,n,i)
dn1=1.66*5*(2500+n(3).^2+0.1*(2500*5*2+2/80*n(3).^2))./(2500+n(3).^2+2/80*n(3).^2+500*(5+5*100)*2)-0.756*n(1); %dn1: mRNA concentration (molec)
dn2 =5*n(1) - 0.756*n(2); %dn2: enzyme concentration (molec)
dn3 =0.23*(i-2*n(3)); %dn3: intracellular IPTG concentration (molec)
dndt = [dn1; dn2; dn3];
return
%ODEs
n0=[1 1 1];
ODEs
for j=1:10
i=100*j %initial IPTG concentration (molec)
options = odeset('RelTol',1e-6,'Stats','off','Abstol',1e-6);
[t,n]=ode23t(@lacO_I_c,[0 450],n0,options,i);
E(:,j) = n(end,2);
end
end
function dndt = numlaco(t,n,k)
dn1 =(1.66*5*(2500+(n(3)/k).^2+0.1*(2500*5*2+2/80*(n(3)/k).^2))./(2500+(n(3)/k).^2+2/80*(n(3)/k).^2+2500*(5+5*100)*2)-0.756*n(1)).^k;
% the combined effect of multiple lac operons on the transcription efficiency factor
dn2 =5*n(1) - 0.756*n(2);
dn3 =0.23*(50-2*n(3));
dndt = [dn1; dn2; dn3];
return
n0=[0 0 0];
options = odeset('RelTol',1e-6,'Stats','off','Abstol',1e-6);
for k=1:3
[t,n]=ode23t(@numlaco,[0 50],n0,options,k)
n(261:end,:)=[]
p(:,k)=n(:,2)
end
end
function dndt = rbs(t,n,i)
dn1 = 1.66*5*(2500+n(3).^2+0.1*(2500*5*2+2/80*n(3).^2))./(2500+n(3).^2+2/80*n(3).^2+2500*(5+5*100)*2)-0.756*n(1);
dn2 =i*n(1) - 0.756*n(2);
dn3 =0.23*(50-2*n(3));
dndt = [dn1; dn2; dn3];
return
n0=[0 0 0];
options = odeset('RelTol',1e-6,'Stats','off','Abstol',1e-6);
[t,n1]=ode23t(@rbs,[0 50],n0,options,0.5);%RBS RL
n1=n1(:,2);
[t,n2]=ode23t(@rbs,[0 50],n0,options,1.0); %RBS R
n2=n2(:,2);
[t,n3]=ode23t(@rbs,[0 50],n0,options,1.5); %RBS RH
n3=n3(:,2)
end
function [tplot,gplot,xplot,lplot] = eqn1st ( g0,x0,l0)
l=l0;g=g0;x=x0;% the initial number of molecules
t = 0; % Time variable.
tplot = zeros(1); % For plotting.
t_stop = 50;
n = 0; % Reaction counter.
n_max = 1000;
while t < t_stop
h(1)=0.82*x;%metabolic exhaustion
h(2)=0.39*x*(1-x/900)/0.28+29.9*0.39*x*(1-x/900)+0.2*x+0.82*x;%substrate consumption
h(3)=29.9*0.39*x*(1-x/900)+0.2*x;%product formation
[u,tau]=U_T(h);% pick the next reaction randomly and generate the reaction time randomly
t = t + tau;%update time
switch u
case 1
x=x-1;
case 2
g=g-1;
x=x+1;
case 3
x=x-1;
l=l+1;
end
n = n + 1;
%record the new values of t and X to vectors
tplot(n+1,:) = t;
gplot(n+1,:) = g;
xplot(n+1,:) = x;
lplot(n+1,:) = l;
end
end
function [tplot1, Y1plot1,Y2plot1,Y3plot1,gplot1,xplot1,lplot1] = eqn2ed(g0,x0,l0,d0,lp0,dp0)
l=l0;d=d0;g=g0;x=x0;
lp=lp0;dp=dp0; % the initial number of molecules
Y1plot1 = lp0;Y2plot1 = dp0; Y3plot1 = lp0/dp0;
r1=200;r2=115;r3=205;
k1=4;k2=50;k3=15;
t = 50;%time variable
tplot1 = zeros(1);
t_stop1 = 100;
n = 0; % Reaction counter.
n_max = 4000;
while t < t_stop1
h(1)=r1*l/(k1+l);
h(2)=r2*l/(k2+l);
h(3)=r3*d/(k3+d);
h(4)=0.82*x;
h(5)=0.39*x*(1-x/900)/0.28+29.9*0.39*x*(1-x/900)+0.2*x+0.82*x;
h(6)=29.9*0.39*x*(1-x/700)+0.2*x;
[u,tau]=U_T(h); % pick the next reaction randomly and generate the reaction time randomly
t = t + tau;%update time
switch u
case 1
l = l - 1;
lp=lp+1;
case 2
l = l - 1;
d=d+1;
case 3
d=d-1;
dp=dp+1;
case 4
x=x-1;
case 5
g=g-1;
x=x+1;
case 6
x=x-1;
l=l+1;
end
n = n + 1;
%record the new values of t and X to vectors
tplot1(n+1,:) = t;
Y1plot1(n+1,:) = lp;
Y2plot1(n+1,:) = dp;
Y3plot1(n+1,:) = lp/dp;
gplot1(n+1,:) = g;
xplot1(n+1,:) = x;
lplot1(n+1,:) = l;
end
end
function [u,t]=U_T(h)
[~,n]=size(h);
aa=sum(h);
r=rand(1,2);
t=(1.0/aa)*log(1.0/r(1));
rr=r(2)*aa;
if h(1)>=rr
u=1
else
for j=2:n
if sum(h(1:j-1))<rr&&sum(h(1:j))>=rr
u=j;
break;
end
end
end
end
[tplot0,gplot0,xplot0,lplot0] = eqn1st( 15000,40,0)%stage 1
a=gplot0(end,1);
b=xplot0(end,1);
c=lplot0(end,1);
[tplot1, Y1plot1,Y2plot1,Y3plot1,gplot1,xplot1,lplot1] = eqn2ed (a,b,c,0,1,1); %stage 2
function [dp,lp,y] = eqnchng( d0,l0,dp0,lp0,es,er)
d=d0;l=l0;
dp=dp0;lp=lp0;
r1=20.0;r2=11.5;r3=20.5;
k1=4;k2=50;k3=15;
t = 0;
tplot = zeros(1);
t_stop = 50;
n = 0;
n_max = 1000;
while t < t_stop
h(1)=r1*es*d/(k1+d);
h(2)=r2*er*d/(k2+d);
h(3)=r3*es*l/(k3+l);
[u,tau]=U_T(h);
t = t + tau;
switch u
case 1
d = d - 1;
dp=dp+1;
case 2
d = d - 1;
l=l+1;
case 3
l=l-1;
lp=lp+1;
end
n = n + 1;
end
y=dp/lp
end
es=10:10:100;
er=10:10:100;
for i=1:length(es)
for j=1:length(er)
[dp,lp,y] = eqnchng(1000,0,1,1,es(i),er(j));
dpo(i,j)=dp;
lpo(i,j)=lp;
yo(i,j)=y;
end
end
%plot
figure(1)
surf(er,es,dpo,'FaceAlpha',0.6)
colormap(cool)
title("L-glutamate molecules",'FontName','Lato','FontSize',16)
ylabel("glutamate racemase",'FontName','Lato','FontSize',10)
xlabel("¦Ã-PGA synthetase",'FontName','Lato','FontSize',10)
zlabel("number of L-glutamate molecules",'FontName','Lato','FontSize',10)
colorbar
figure(2)
surf(er,es,lpo,'FaceAlpha',0.6)
colormap(cool)
title("D-glutamate molecules",'FontName','Lato','FontSize',16)
ylabel("glutamate racemase",'FontName','Lato','FontSize',10)
xlabel("¦Ã-PGA synthetase",'FontName','Lato','FontSize',10)
zlabel("number of D-glutamate molecules",'FontName','Lato','FontSize',10)
colorbar
figure(3)
surf(er,es,yo,'FaceAlpha',0.6)
colormap(autumn)
title("Ratio of L-glutamate and D-glutamate",'FontName','Lato','FontSize',16)
ylabel("glutamate racemase",'FontName','Lato','FontSize',10)
xlabel("¦Ã-PGA synthetase",'FontName','Lato','FontSize',10)
zlabel("L/D",'FontName','Lato','FontSize',10)
colorbar
array(:,:,1)=lpo;
array(:,:,1)=dpo;
function h = stacked_bar3(array)
dims = size(array);
ns = dims(3);
nr = dims(1);
nc = dims(2);
ax = newplot;
co = ax.ColorOrder;
h = gobjects(1,ns);
view(ax,3)
xlim(ax,[.5 nc+.5])
ylim(ax,[.5 nr+.5])
bw = .4;
offmat = [-bw, +bw, 0; ...
-bw, -bw, 0; ...
+bw, -bw, 0; ...
+bw, +bw, 0];
sidemat = [1, 2, 2, 1; ...
2, 3, 3, 2; ...
3, 4, 4, 3; ...
4, 1, 1, 4] ...
+ repmat([0, 0, 4*nr*nc, 4*nr*nc],[4, 1]);
topmat = (1:4) + 4*nr*nc;
top = zeros(dims(1:2));
for s = 1:ns
bottom = top;
top = bottom + array(:,:,s);
verts = zeros(4*nr*nc*2, 3);
faces = ones(5*nr*nc, 4);
for r = 1:nr
for c = 1:nc
vindex = 4*(r-1 + nr*(c-1));
lindex = 5*(r-1 + nr*(c-1));
rindex = 4*(r-1 + nr*(c-1));
verts(vindex + (1:4)', :) = repmat([c,r,bottom(r,c)],[4,1]) + offmat;
verts(vindex + 4*nr*nc + (1:4)', :) = repmat([c,r, top(r,c)],[4,1]) + offmat;
faces(lindex + (1:5)',:) = rindex + [sidemat; topmat];
end
end
cix = 1+mod(s-1, size(co,1));
h(s) = patch('Vertices', verts, ...
'Faces', faces, ...
'FaceColor', co(cix,:), ...
'Parent', ax);
bottom = top;
end
end
end
function c = model1(beta ,t)
a = beta(1);%Biomass when t=0
b = beta(2);%maximum cell growth rate
c = (a* exp(b*t))./[1-(a/d)*(1-exp(b*t))];
xlsread('E:\ previous_data.xlsx',1,'B1:B13')';
xlsread('E:\ previous_data.xlsx',1,'A1:A13')';
xlsread('E:\ previous_data.xlsx',1,'B14')';%carrying capacity of the bioreactor,obtained from the data
beta0=[20 0.1];
nlintool(t,c,'model1',beta0);
end
It gives this error: lacO(t, n)
Unrecognized function or variable 't'. I'm not sure how to fix it
  1 Comment
Cris LaPierre
Cris LaPierre on 16 Aug 2022
You have defined a function, so when you call it, you must supply the inputs t and n.
However, have you copied your code correctly? I can't run what you have shared due to an invalid expressoin in your first call to ode23t. Your code is several nested functions, but the calling function, lacO, appears to be a recursive function, since it calls itself. Was that the intention?
As and example, it looks like lacO should just be this
n0=[0 0 0]; % Initial conditions
options = odeset('RelTol',1e-6,'Stats','off','Abstol',1e-6); % ODE Options
[t,n]=ode23t(@lacO,[0 50],n0,options)
t = 268×1
0 0.0005 0.0015 0.0024 0.0034 0.0083 0.0192 0.0301 0.0410 0.0519
n = 268×3
0 0 0 0.0000 0.0000 0.0056 0.0001 0.0000 0.0168 0.0002 0.0000 0.0280 0.0003 0.0000 0.0392 0.0007 0.0000 0.0952 0.0016 0.0001 0.2199 0.0024 0.0002 0.3440 0.0033 0.0003 0.4674 0.0042 0.0005 0.5903
function dndt = lacO(t,n)
dn1=1.66*5*(2500+n(3).^2+0.1*(2500*5*2+2/80*n(3).^2))./(2500+n(3).^2+2/80*n(3).^2+500*(5+5*100)*2)-0.756*n(1); %dn1: mRNA concentration (molec)
dn2 =5*n(1) - 0.756*n(2); %dn2: enzyme concentration (molec)
dn3 =0.23*(50-2*n(3)); %dn3: intracellular IPTG concentration (molec)
dndt = [dn1; dn2; dn3];
end

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 16 Aug 2022
Edited: Star Strider on 16 Aug 2022
I only see one call to the ‘lacO’ function and the code calling it runs correctly, after the ‘@’ sign is removed in front of the ode23t call —
%ODEs
n0=[0 0 0]+eps; % Initial conditions
options = odeset('RelTol',1e-6,'Stats','off','Abstol',1e-6); % ODE Options
[t,n]=ode23t(@lacO,[0 50],n0,options);
figure
plot(t,n)
grid
function dndt = lacO(t,n)
dn1=1.66*5*(2500+n(3).^2+0.1*(2500*5*2+2/80*n(3).^2))./(2500+n(3).^2+2/80*n(3).^2+500*(5+5*100)*2)-0.756*n(1); %dn1: mRNA concentration (molec)
dn2 =5*n(1) - 0.756*n(2); %dn2: enzyme concentration (molec)
dn3 =0.23*(50-2*n(3)); %dn3: intracellular IPTG concentration (molec)
dndt = [dn1; dn2; dn3];
end
Also, the return call at the end of a function definition is obsolete. It needs to replaced with an end instead.
The entire code either needs to be within a function definition (and then call that function to execute the code), or all the functions must be after the ode23t call if in a script.
.
  2 Comments
Star Strider
Star Strider on 16 Aug 2022
It works for me.
We can’t run the code because we don’t have the Excel files, and even if we did, I doubt that’s where the problem is.
Remove all the return calls and replace them with end wherever they occur.
The only other thing I can think of is to run this line from a script or your Command Window —
which ode23t -all
and consider doing the same for other functions if subsequent problems arise in your code and that’s a relevant concern.
That should only return something like the following —
which ode23t -all
/MATLAB/toolbox/matlab/funfun/ode23t.m
If it returns anything else, that could point to the problem.
.

Sign in to comment.


Torsten
Torsten on 16 Aug 2022
After deleting the @ before ode23t, the code with @locO works for me.
%ODEs
n0=[0 0 0]; % Initial conditions
options = odeset('RelTol',1e-6,'Stats','off','Abstol',1e-6); % ODE Options
[t,n]=ode23t(@lacO,[0 50],n0,options);
plot(t,n)
%functions
function dndt = lacO(t,n)
dn1=1.66*5*(2500+n(3).^2+0.1*(2500*5*2+2/80*n(3).^2))./(2500+n(3).^2+2/80*n(3).^2+500*(5+5*100)*2)-0.756*n(1); %dn1: mRNA concentration (molec)
dn2 =5*n(1) - 0.756*n(2); %dn2: enzyme concentration (molec)
dn3 =0.23*(50-2*n(3)); %dn3: intracellular IPTG concentration (molec)
dndt = [dn1; dn2; dn3];
end
  2 Comments
Torsten
Torsten on 16 Aug 2022
Edited: Torsten on 16 Aug 2022
You get an error message when you use the above code ? But it runs without problems in R2022 a.
In the code you posted, there is a wild mixture of functions and script parts. Take the script parts together, put them at the head of your code and let the functions follow below.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!