Sei sulla pagina 1di 2

Tmax = 100000;

p = 0.10;
Nc = 20;
Fix = 5;
N = 100000;

Time_to_clear = zeros(N,1);
All_infected = zeros(N,1);
Num_infected= zeros(N,1);

for k=1:N;
T = 0 ;
Infected_comps = [1
zeros(Nc-i , 1)];

Infected_at_least_once = Infected_comps;
Ninfected = sum(Infected_comps);

while Ninfected > 0 8: T < Tmax;


T = T+1;
P_infection = 1-(1-p)^Ninfected;

Infected_comps = max( Infected_comps, (rand(Nc,1) < P_infection) );


Infected_at_least_once = max(Infected_at_least_once, Infected_comps);

Compfix = 1; Ncompfix = 0;
while (Campfix <= Nc) Kc (Ncompfix < Fix);
if Infected_comps(Compfix)==1;
Infected_comps (Compfix) =0;
Ncompfix = Ncompfix+1;
end;
Compfix = Campfix + 1;
end;
Ninfected = sum(lnfected_comps);
end;

Time_to_clear(k) = T;

All_infected(k) ( sum(Infected_at_least_once)==Nc );
Num_infected(k) ( sum(Infected_at_least_once) );
end;

disp([’The expected time until all computers are fixed is ’ , ’approximately ’,


num2str( mean(Time_to_clear) ), ’ days’]);

disp([’The probability that each computer gets infected at least ’ ,’once is


approximately ’, num2str( mean(All_infected) )]);

disp([’The expected number of computers that get infected is ’ , ’approximately ’,


num2str( mean(Num_infected) )]);

-----------------------------------------------------------------------------------
--------------------------------------------------
output
-----------------------------------------------------------------------------------
--------------------------------------------------
The expected time until all computers are fixed is approximately 73 days
The probability that each computer gets infected at least once is approximately
0.0012
The expected number of computers that get infected is approximately 2.98

Potrebbero piacerti anche