필터 지우기
필터 지우기

How to terminate simulation and output timesteps to termination

조회 수: 1 (최근 30일)
Colin Lynch
Colin Lynch 2018년 2월 20일
Hello everyone!
I am attempting to count the number of time steps it takes for a simulation to reach equilibrium, and once its there to terminate the simulation. Here, the simulation reaches equilibrium when n(t+1) = n(t) AND when S(t+1) = S(t). The following code runs the simulation until t = T, but I want it to stop when it reaches the above conditional and then I want it to output eq = t where t is the amount of time it took to reach equilibrium. Does anyone know how to make this happen, as this code is spitting out errors?
function [n, S] = simulate_dynamics(n0, S0, dt, T, A, B, C, D, beta, thetaI, thetaC, lambda, alpha, K)
eq = []
S(1) = S0;
n(1) = n0;
for t = 1:T
pStart = A + B * (S(t).^2./(S(t).^2 + thetaI.^2));
pStop = C + D * (1 ./ (1 + exp(beta*(S(t)-thetaC))));
n(t+1) = n(t) + dt * (pStart * (1 - n(t)) - pStop*n(t));
S(t+1) = S(t) + dt * (lambda*S(t).^alpha - K*n(t));
% keep both variables inside [0 1]
if S(t+1) > 1
S(t+1) = 1;
end
if n(t+1) > 1
n(t+1) = 1;
end
if S(t+1) < 0
S(t+1) = 0;
end
if n(t+1) < 0
n(t+1) = 0;
end
if n(t+1) = n(t) & S(t+1) = S(t)
eq = t
return
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 General Physics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by