Creating a loop to simulate model

16 vues (au cours des 30 derniers jours)
user
user le 4 Sep 2022
Hello,
I am seeking to create a loop that simulates the following function, while keeping track of its output. The code i have provided has a boolean output (Response) of either 0 or 1 and I would like to be able to simulate the model described in my code a large number of times while keeping track of the frequency of each boolean output. Any help would be appreciated.
function Response = testingforparam
r1 = unifrnd(0.27, 1.06)
r2 = unifrnd(0.57, 1.30)
function C=kinetics(theta,t)
%c0 denotes the intial conditions of each compartment
c0=[0;0;(100)];
[T,Cv]=ode45(@DifEq,t,c0);
function dC=DifEq(t,c)
dcdt=zeros(3,1);
dcdt(1)= 20.*c(3)+(r1).*c(1).*(1-(c(1)/(5*10^9)))-0.02.*c(1)-((69.7).*c(1)/(1+0.01*c(1)));
dcdt(2)= 20.*c(3)+(r2).*c(2).*(1-(c(2)/(1*10^9)))-0.02.*c(2)-((9/11)*(57.02).*c(2)/(1+0.01*c(2)));
dcdt(3)= 0.02.*c(1)+0.02.*c(2)-20.*c(3)-20.*c(3)-39.12.*c(3);
dC=dcdt;
end
C=Cv;
end
%The following is the data obtained by Join-Lambert et al used in fitting
%the model
t = [0,0.3,24,48];
Liver = [0;101329.8755;9983499.7496;3397799162.7540];
Spleen = [0;365778.6821;7088832.4672;169779424.6359];
Blood = [0;23.2338;92.2555;16841.2063];
c = [Liver, Spleen, Blood];
theta0=[1;1;1];
[theta,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@kinetics,theta0,t,c);
tv = linspace(min(t), max(t), 4);
Fit = kinetics(theta, tv);
LiverFit = Fit(:,1);
SpleenFit = Fit(:,2);
BloodFit = Fit(:,3);
Final = (LiverFit(end)+SpleenFit(end)+BloodFit(end));
% Using boolean notation, 1 is a positive reponse, 0 is a zero reponse
if Final>2 Response = 1;
else Response = 0;
end;
end

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Sep 2022
N = 5000;
Responses = zeros(N, 1);
for K = 1 : N
Responses(K) = testingforparam;
end
mean_ones = mean(Responses);

Plus de réponses (0)

Catégories

En savoir plus sur Cardiology dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by