the results from one timestep feed into the subsequent timestep?

2 次查看(过去 30 天)
Hi,
I have the following equaiton:
dCs(t)=(I*Ea/Vd)-(Ke*Cs(t));
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!

回答(1 个)

Chaitanya Mallela
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 个评论
Wesser
Wesser 2021-3-21
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 script...one 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!!
Serum(1)=0;
startpt=2;
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)
startpt=startpt+1;
for j = startpt:timesteps
Serum(j,column) = Serum(j-1,column) + (I(j,column) * Ea / Vd) - (Ke(j,column) * Serum(j-1,column));
end
end
end
StartExposure(column)=startpt;
end

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by