How to write code for repetitive process?
2 次查看(过去 30 天)
显示 更早的评论
Hello.
Given:
Variable components: species_1 and species_2;
Initial values: species_1=1000 g and species_2=200 g;
Process parameters: timecut=2 hour, timecon=1hour, kf=0.1 1/hour
The components are related to each other by a reaction according to the law of mass action:
species_1 -> species_2: kf*species_1
In the time interval 0<=time<=timecut, the mass of the component species_1 decreases while the mass of the component species_2 increases. At the point time=timecut, the masses of the components return to their initial values. Two sawtooth patterns are formed on the charts: one sawtooth on chart for species_1 and another inverted sawtooth on chart for species_2.
Then, during the timecon, the masses of components retain their original values: "shelves" are formed. Codes in the Simbiology Builder:
Trigger: time>=timecut
Event FCNS:
kf=0
species_1=1000
species_2=200
If time>=timecut+timecon and kf=0.1, the mass of the species_1 component decreases and the mass of the species_2 component increases. No saw teeth and shelves are formed.
How should the code be written in Simbiology so that the "tooth-shelf" process are repeated n times?
0 个评论
采纳的回答
Tatiana Kovaleva
2024-10-2
1 个评论
Arthur Goldsipe
2024-10-2
Thanks for sharing. I looked at the file, but I don't yet understand what you're asking. I think you're asking how you can modify the event so that the simulation looks different in some way. But I don't understand what you want it to look like. Can you share a drawing or some other description of your desired simulation results?
更多回答(2 个)
Arthur Goldsipe
2024-9-30
If I understand your question, you're asking how to create an event that fires repeatedly. I'm not sure exactly what kind of repeating schedule you need, but here's how you could have it repeat every "timecut" hours:
- Add a parameter n=1.
- Set Constant=false for n.
- Update your event trigger something involving n, for example: time >= n*timecut+timecon
- Add an event function to your event to increment n, for example: n = n+1
If you only want the event to be triggered 3 times, you could do that as follows:
- Add a parameter nmax=3.
- Update your event trigger to: time >= n*timecut+timecon && n <= nmax
6 个评论
Arthur Goldsipe
2024-10-3
Ah, I think I finally understand what you want to do. Let me rephrase and see if this makes sense.
You want to create a concentration profile with "teeth" that repeat at regular intervals, with flat lines between those teeth. And you want to do that by specifying (1) the width of each tooth (timecut) and (2) the interval between teeth (timecon).
In that case, I've attached a modified version of your project that does that. See if that makes sense and does what you want.
Tatiana Kovaleva
2024-10-2
编辑:Tatiana Kovaleva
2024-10-2
1 个评论
Arthur Goldsipe
2024-10-2
Yes, I was able to download the file when you posted it previously. On that post, I added a comment and asked a followup question.
I've been having some trouble with this website today. If you can't see my comment, you can also try sending me a message through my profile. (Note to others who read this: Please try posting your questions publicly rather than contacting me directly through my profile, since I am not always available to answer such direct questions.)
另请参阅
类别
在 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!