How to write code for repetitive process?

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?

 Réponse acceptée

Tatiana
Tatiana le 2 Oct 2024

0 votes

In the attached file n=n+1.5

1 commentaire

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?

Connectez-vous pour commenter.

Plus de réponses (2)

Arthur Goldsipe
Arthur Goldsipe le 30 Sep 2024

0 votes

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 commentaires

Tatiana
Tatiana le 2 Oct 2024
The increment n=n+1 depends on the parameter timecut. For example, if timecut=2, then one have to use n=n+1.5 to obtain a random-valued sequence of events. If n=n+1 then the timecut spontaneously reduces to 1 in all events except the first..
Is there any way to keep the increment n=n+1 independent of time?
Is there any way to send you the Simbiology file, or at least the graphs produced?
I'm sorry, but I don't understand how you want to determine the schedule of the events. If you can describe it in more detail, I can probably offer a more concrete suggestion.
Can you share your files publicly? If so, you should be able to attach files to your question or to a comment.
Tatiana
Tatiana le 3 Oct 2024
I would like to have all the saw teeth equal to the initial tooth, while using the increment n=n+1. I would not like to set the equality of the teeth by selecting the increment step. For example, n=n+1.5, n=n+0.6 and other similar adjustments.
Tatiana
Tatiana le 3 Oct 2024
I would like to have all the saw teeth eqaul to the initial tooth, while using the increment n=n+1.
If i set parameter timecut=2 then on the graph the timecut will be equal to 1 for all teeth except the first tooth. To set the teeth equal in size i have to use the increment n=n+1.5.
I would not like to set the eqality of the teeth by selecting the increment step. For example, n=n+1.5, n=n+0.6 and other similar adjustments.
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
Tatiana le 3 Oct 2024
The modified version of the project works. Thank you for your help and patience.

Connectez-vous pour commenter.

Tatiana
Tatiana le 2 Oct 2024
Modifié(e) : Tatiana le 2 Oct 2024

0 votes

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 commentaire

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.)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Extend Modeling Environment dans Centre d'aide et File Exchange

Produits

Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by