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

5 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Arthur Goldsipe
Arthur Goldsipe am 3 Sep. 2021
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

Weitere Antworten (0)

Communitys

Weitere Antworten in  SimBiology Community

Kategorien

Mehr zu Extend Modeling Environment finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by