https://pu​bs.acs.org​/doi/abs/1​0.1021/j10​0540a008 - Official article link for implementing Gillespie algoirthm

Réponses (1)

Kevin - you will need to review the following block of code
mu = sum(r(2)*a0 <= cumsum(a));
t = t + tau;
switch mu
case 1
X(mu) = X(mu) - 1;
end
n = n + 1;
Xplot(mu,n+1) = X(mu);
When I run your script, the mu variable is set to 4 (on the first iteration of the while loop). Since this case isn't handled in the switch statement (not sure why you only handle the case where mu is one, is this intentional? do you even want a switch here?) then there isn't any change to X which is a scalar (assigned the value of one previously). And so the line
Xplot(mu,n+1) = X(mu);
will generate the above error since you are trying to access an element using an index (4) that is invalid for your array (of length 1). What is it that you really want to be doing at these lines? How should mu and X work together?

Catégories

Produits

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by