Simbiology: Generate reactions with a loop
4 views (last 30 days)
Show older comments
I'm creating a pk model with the following reaction rate: 'Dose*ka*e^(-ka*(time-TimeOfDose))'. I haven't been able to figure out how to do this in Simbiology, other that to just create an absorbance reaction for each dose. However, I need a lot of doses, and to be able to easily change the number of doses. I figured that I would use a loop to generate the correct number of reactions, however I'm getting some errors when trying this.
Here is the code:
for i = 0:(nDose - 1)
r(i) = addreaction(m1, 'null -> Central.Drug');
set(r(i), 'ReactionRate', Dose*ka*e^(-ka*(time-(i*7)));
end
With 7 being the dosing interval. This gives the error:
Subscript indices must either be real positive integers or logicals.
0 Comments
Answers (1)
Arthur Goldsipe
on 2 Oct 2017
The immediate problem is that MATLAB uses 1-based indexes when indexing into vectors, so you need to make sure that you start at r(1) instead of r(0).
But it sounds like you're trying to model first-order absorption of a drug. There is a simpler way to do that in SimBiology. Basically, add an intermediary species and reaction to your model to account for the first order absorption. For example, if you call the species Dose and put the species in compartment Central, then add a reaction "Central.Dose -> Central.Drug" with reaction rate "ka*Central". Finally, implement your dosing using a dose object with "Dose" as the target.
2 Comments
Arthur Goldsipe
on 10 Oct 2017
I guess I still don't understand why you want to use the analytical/explicit solution to differential equations with SimBiology. I'll show you one way that uses events below. But I think it's going to be a lot more complicated than just letting SimBiology solve the equations for you. If you have additional follow-up questions, I suggest contacting me through my profile page. I don't get notified when you post a comment here.
m1 = sbiomodel('m1');
m1.addparameter('Dose', 2.0);
m1.addparameter('ka', 0.1);
m1.addparameter('doseTerm', 0.0, 'ConstantValue', false);
m1.addrule('doseTerm = Dose', 'initialAssignment'); % t0 dose
r1 = m1.addreaction('null -> Central.Drug');
r1.ReactionRate = 'doseTerm*ka*exp(-ka*time)';
m1.addparameter('doseInterval', 7);
m1.addparameter('doseCounter', 1, 'ConstantValue', false);
m1.addparameter('nDose', 3);
m1.addevent('time > doseCounter*doseInterval && doseCounter < nDose', ...
{'doseTerm = doseTerm + Dose*ka*exp(ka*doseCounter*time)', ...
'doseCounter = doseCounter + 1'});
Communities
More Answers in the SimBiology Community
See Also
Categories
Find more on Scan Parameter Ranges in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!