Clear Filters
Clear Filters

How to write code for repetitive process?

92 views (last 30 days)
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?

Accepted Answer

Tatiana Kovaleva
Tatiana Kovaleva on 2 Oct 2024 at 15:54
In the attached file n=n+1.5
  1 Comment
Arthur Goldsipe
Arthur Goldsipe on 2 Oct 2024 at 17:55
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?

Sign in to comment.

More Answers (2)

Arthur Goldsipe
Arthur Goldsipe on 30 Sep 2024 at 15:00
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:
  1. Add a parameter n=1.
  2. Set Constant=false for n.
  3. Update your event trigger something involving n, for example: time >= n*timecut+timecon
  4. 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:
  1. Add a parameter nmax=3.
  2. Update your event trigger to: time >= n*timecut+timecon && n <= nmax
  6 Comments
Arthur Goldsipe
Arthur Goldsipe on 3 Oct 2024 at 17:21
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
Tatiana Kovaleva on 3 Oct 2024 at 18:41
The modified version of the project works. Thank you for your help and patience.

Sign in to comment.


Tatiana Kovaleva
Tatiana Kovaleva on 2 Oct 2024 at 18:04
Edited: Tatiana Kovaleva on 2 Oct 2024 at 18:20
In the attached file n=n+1.5
I'm not sure if my attached file "davr.sbproject" has reached you. I don't know what to do.
  1 Comment
Arthur Goldsipe
Arthur Goldsipe on 2 Oct 2024 at 19:12
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.)

Sign in to comment.

Categories

Find more on Extend Modeling Environment in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!