How do I generate a rectangular pulse for an input species in Simbiology?

1 次查看(过去 30 天)
I would like to pulse an input species in Simbiology. I read in a previous answer that repeated assignments can be used to accomplish this. However, I am unclear how to do this. The following is MATLAB code for generating the pulse that I would like the species concentration to follow:
t = 0:1/1e3:60;
d = [0:2:60;sin(2*pi*0.05*(0:2:60))]';
x = @rectpuls;
y = pulstran(t,d,x);
plot(t,y)
hold off
xlabel('Time (s)')
ylabel('Waveform')
Output:
Any help is appreciated as to how I can accomplish this in Simbiology.
Aaron

采纳的回答

Arthur Goldsipe
Arthur Goldsipe 2021-9-3
I would not use rules to implement discontinuous changes in a SimBiology model. The ODE solver should be restarted whenever there are discontinuities, or else you may encounter problems like inaccurate results and slower simulations.
If you only needed to increase the value of a species, I would suggest using a SimBiology dose. But for more general kinds of step changes, I suggest using events. You can find one example of that here.
I don't know exactly what kind of pulse you want to generate. The plot I get when running the code you provide is different. But here's one way you could build a SimBiology model to reproduce what you plot. I use an event to toggle the concentration of a species between 0 and 1, and the event also determines when the next event will occur.
modelObj = sbiomodel("pulse");
compartmentObj = addcompartment(modelObj, "c");
addspecies(compartmentObj, "x", 0);
addparameter(modelObj, "nextPulseTime", 9.5, "Constant", false);
addparameter(modelObj, "stopPulse", 30.5);
addparameter(modelObj, "eventCount", 0, "Constant", false);
addparameter(modelObj, "numEvents", 22);
addevent(modelObj, "eventCount < numEvents && time >= nextPulseTime", ...
["x = 1 - x", ...
"nextPulseTime = nextPulseTime + 1", ...
"eventCount = eventCount + 1"]);
configset = getconfigset(modelObj);
configset.StopTime = 60;
configset.SolverOptions.MaxStep = 0.1;
configset.RuntimeOptions.StatesToLog = "x";
simdata = sbiosimulate(modelObj);
sbioplot(simdata);
I hope that helps.
-Arthur

更多回答(0 个)

社区

更多回答在  SimBiology Community

类别

Help CenterFile Exchange 中查找有关 Extend Modeling Environment 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by