Unable to perform assignment because the left and right sides have a different number of elements.

1 view (last 30 days)
My questions deals with ODEs and enzyme catalyzed reactions. My v1 needs to vary from 0.01:2 and I need to produce a graph of P* vs v1. (P* is related to dy/dt(2) which is the rate of chnage). When I try to code this in, I get the error that left and right sides have different number of elements.
clear
%Vmax values for each reaction step
v1=0.01:0.01:2;
v2=1;
%Km values for each reaction step
K1=1;
K2=1;
%initial values (0.3,0.2,0.1). These can be changed to 6,4,4
s10=1;
s20=0;
%simulation duration
Tfinal=7;
clf
hold on
tspan = [0 Tfinal];
y0 = [s10 s20];
[t,y] = ode45(@(t,y) odefcn(t,y,v1,v2,K1,K2), tspan, y0);
plot(v1,y(:,2),'r',"LineWidth",1)
xlabel("time (s)")
ylabel("concentration (mM)")
legend('P', 'P*')
%This function is the original complete system of ODEs
function dydt = odefcn(t,y,v1,v2,K1,K2)
dydt = zeros(2,1);
dydt(1) = v2*y(2)/(K2+y(2))-v1*y(1)/(K1+y(1));
dydt(2) = v1*y(1)/(K1+y(1))-v2*y(2)/(K2+y(2));
end

Accepted Answer

Alan Stevens
Alan Stevens on 8 Feb 2022
Like this?
clear
%Vmax values for each reaction step
v1=0.01:0.01:2;
v2=1;
%Km values for each reaction step
K1=1;
K2=1;
%initial values (0.3,0.2,0.1). These can be changed to 6,4,4
s10=1;
s20=0;
%simulation duration
Tfinal=7;
tvals = 0:numel(v1)-1;Tfinal; %%%%%%%% Assumes v1 changes at equal intervals of time
clf
hold on
tspan = tvals;
y0 = [s10 s20];
[t,y] = ode45(@(t,y) odefcn(t,y,v1,v2,K1,K2,tvals), tspan, y0);
plot(v1,y)
xlabel("time (s)")
ylabel("concentration (mM)")
legend('P', 'P*')
%This function is the original complete system of ODEs
function dydt = odefcn(t,y,v1,v2,K1,K2,tvals)
V1 = interp1(tvals,v1,t);
dydt = zeros(2,1);
dydt(1) = v2*y(2)/(K2+y(2))-V1.*y(1)/(K1+y(1));
dydt(2) = V1*y(1)/(K1+y(1))-v2*y(2)/(K2+y(2));
end

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!