Chaning value of parameter in s-function mid-simulation
이전 댓글 표시
Hey there :)
I have a question regarding how to change a parameter in an s-function in real time.
As my s-function runs, it calculates a cell concentration. After 20 hours I want it to save the exact value of the cell concentration at that time and save it for later. This value is needed to calculate a cell decline after the 20 hours mark. I can't seem to save the parameter permanent, it appears to be reset for each iteration of the ode-solver, thus my decline expression ends up wrong. I fell like it should be a simple question of saving the concentration as a new value, but I can't get anything to work so far. I hope some of you can help me with this :)
I have attached a shortened bit of my code, to hopefully illustrate the problem.
Best regards, Frederik
function sys=mdlDerivatives(t,x)
%The simulation runs in a time interval of 0 to 30 hours.
%Growth of cells:
growth = (X*(1-xi)*mu);
%time used for decline equation
t1 = 20-t
%Decline of cells, given by the expression N(t) = N(0)*exp(-gamma*t), N(0)
%is renamed to X_decay. This value is initially set to 0 (no decline) from the script.
decline = (X_decay*exp(-gamma*t1);
%I want the value of X_decay to change at the 20 hours mark. I want it to
%take on the value of X (cell concentration) at the given time, as this
%will be equal to N(0) for the decline expression, which should be used
%in the time interval 20-30 hours.
if t==20
X_decay = X
end
%Until the 20 hour mark, cells will only grow, afterwards, some will die.
if t<20
dxdt(1) = growth;
elseif t>20
dxdt(1) = growth-decline;
end
sys = [dxdt(1)];
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 General Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!