How do I generate a rectangular pulse for an input species in Simbiology?
조회 수: 2 (최근 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
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Extend Modeling Environment에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!