Help with stochastic model by use of the Gillespie algorithm
Show older comments
The code just fails for some reason and I can't pinpoint why
num_reactions = 50000;
cIprot = zeros(num_reactions,1);
cIrna = zeros(num_reactions,1);
croprot =zeros(num_reactions,1);
crorna = zeros(num_reactions,1);
cIprot (1) = 0;
cIrna (1)= 0;
croprot(1) = 0;
crorna (1)= 0;
time = zeros(num_reactions,1);
total_time = 1; % total time in seconds
i=1;
while (time(i) < total_time)
for i=1:num_reactions
v1=50*cIrna(i);
v2=1.2*cIprot(i);
v3=50*(1-(((croprot(i))^2)/(100+(croprot(i))^2)));
v4=1.2*cIrna(i);
v5=50.*crorna(i);
v6=0.8.*croprot(i);
v7=50*(1-(((cIprot(i))^2)/(100+(cIprot(i))^2)));
v8=0.8*crorna(i);
V = [v1 v2 v3 v4 v5 v6 v7 v8];
end
Rtot= (v1+v2+v3+v4+v5+v6+v7+v8);
alpha0 = sum(V);
y = rand();
y_mod = alpha0*y;
next_rxn = 0;
for j=1:num_reactions % iterate over reactions
if y_mod < sum(V(1:j))
next_rxn = j; % next reaction is j
break; % exit loop
end
end
if (next_rxn == 1)
cIprot(i+1) = cIprot(i) + 1;
elseif (next_rxn == 2)
cIprot(i+1) = cIprot(i) - 1;
elseif (next_rxn == 3)
cIrna(i+1) = cIrna(i) + 1;
elseif (next_rxn == 4)
cIrna(i+1) = cIrna(i) - 1;
elseif (next_rxn == 5)
croprot(i+1) = cIrna(i) + 1;
elseif (next_rxn == 6)
croprot(i+1) = cIrna(i) - 1;
elseif (next_rxn == 7)
crorna(i+1) = crorna(i) + 1;
elseif (next_rxn == 7)
crorna(i+1) = crorna(i) - 1;
else
disp('Something went wrong!');
end
delta_t = -log(y) / Rtot;
time(i+1) = time(i) + delta_t;
end
plot (time,cIrna)
Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!