Clear Filters
Clear Filters

the results from one timestep feed into the subsequent timestep?

7 views (last 30 days)
I have the following equaiton:
This is a single compartment toxicological model. I want to generate what the dCs would be at 6month timesteps for 50 years. However the results are additave/compounding with time.
So for example:
at (t)=1, Cs(t)=0, and dCs(t) ends up being 12;
at (t)=2, Cs(t)=12...the result from the first timestep, and dCs(t) ends up being 23;
This pattern continues until 100 time steps have passed. All the other variable in the equation are fixed. How would I code this in a way where the results from one timestep feed into the subsequent timestep?
Many thanks for any and all help!

Answers (1)

Chaitanya Mallela
Chaitanya Mallela on 2 Feb 2021
You can implement this equation inside a MATLAB function block in Simulink with dCs(t) output given as a feedback input to the MATLAB function block using a time step delay.
  1 Comment
Wesser on 21 Mar 2021
Hi Chaitanya,
Thanks for the reply. I'm still stuck on this front. Below is my code where I'm trying to attempt what I initially described. In essence, I want the Serum equation to start at later and later time intervals until the final predicted Serum(98) no longer exceeds the measured Serum_blood. The columns are individual people and the rows are 6mo intervals between 1970 and 2018. So in the first iteration of the for loop, the simulation starts at t=2, then if the final predicted Serum(98) is greater than the measured Serum_blood, then start the loop again at t=3 (startpt=startpt+1), and repeat until the final predicted value is no longer greater than the measured value. The code runs...but it's taking days for the code to run. I've done a tic/toc of the rest of the code (not shared) and it takes only fractions of a second. Below is the problem segment of the larger code. Is there a way to iteratively step forward in time with a more efficient that will be able to execiute faster?
Also, for the output of the model, I'm trying to save WHEN in time the final iteration of the for-loop began. For example, if the model had to iterate 15 times in the while-loop before Serum(98) no longer exceeds the measured Serum_blood, then I'd want to save that time, being 1986 (16 times steps after the model initially began at. Essentially, I'm trying to back out the start of human exposure to contamination. That is that the last row (StartExposure(column)=startpt;) is hopefully doing?
Thank you thank you for any and all help with this!!
for column = (1:ncolumn)
for t = (startpt:timesteps)
Serum(t,column) = Serum(t-1,column) + (I(t,column) * Ea / Vd) - (Ke(t,column) * Serum(t-1,column));
while Serum(98,column)>Serum_blood(column)
for j = startpt:timesteps
Serum(j,column) = Serum(j-1,column) + (I(j,column) * Ea / Vd) - (Ke(j,column) * Serum(j-1,column));

Sign in to comment.


Find more on General Applications in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!