Suppose that a certain type of bacteria divides (into two) in a given time perio
ID: 2082187 • Letter: S
Question
Suppose that a certain type of bacteria divides (into two) in a given time period with a probability of 75%, and that if it does not divide, it dies. The rand function is useful for simulations of probability because it returns a random number between 0 and 1. Therefore, you could simulate the likelihood of a bacterium dividing by checking if the rand function returns a number less than 0.75 (and if so, the bacterium divides and lives!) You want to simulate a number of generations of bacterial growth. Starting with one bacterium, suppose that it divides into two with probability p = 0.75, and if it does not divide, it dies. In the next generation, the offspring will also divide or die (independently) with a probability of p = 0.75. If no bacteria survive, the colony becomes extinct. To get a good idea of the population, you will need to run this simulation many times. The best way to approach this problem (and many like it) is to start small. (I like to think of this asExplanation / Answer
close all,
clear all,
clc,
SurvivalProb = 0.75;
%%%%%% Single Bacteria Lives or Dies %%%%%%%%%%%%%
No_of_Simulations = 10;
Initial_No_of_Bacteria=10;
BacteriaGrowth=[];
for i=1:No_of_Simulations
BacteriaGrowth(i) = Initial_No_of_Bacteria;
No_of_Bacteria = Initial_No_of_Bacteria;
for j=1:No_of_Bacteria
tempProb = rand;
if (tempProb >= SurvivalProb),
BacteriaGrowth(i) = BacteriaGrowth(i)+2; % Bacteria diviedes and increment by 2.
No_of_Bacteria = No_of_Bacteria+1;
else
BacteriaGrowth(i) = BacteriaGrowth(i)-1; % bacteria Dies and decrement by 1.
No_of_Bacteria = No_of_Bacteria-1;
end
end
end
figure,
plot(BacteriaGrowth); title('Bacterial Growth Vs. Simultion'); xlabel('---- Simul;ation No. ---->'); ylabel('---- No. of Bacteria --->');
%%%%%% Genetical Growth %%%%%%%%%%%%%
Initial_No_of_Bacteria=1000;
No_of_Bacteria=Initial_No_of_Bacteria;
Generation = [];
TotalBacteria=[];
for i=1:3
Generation(i)=0;
TotalBacteria(i)=0;
end
Generation(1) = Initial_No_of_Bacteria;
TotalBacteria(1) = Initial_No_of_Bacteria;
%%%%%%%%%%%%% Generation-1 %%%%%%%%%%%
BacteriaGrowth(1) = Initial_No_of_Bacteria;
No_of_Bacteria = Initial_No_of_Bacteria;
tempGen=0;
tempDie=0;
for j=1:No_of_Bacteria
tempProb = rand;
if (tempProb >= SurvivalProb),
No_of_Bacteria = No_of_Bacteria+2;
tempGen=tempGen+2;
else
No_of_Bacteria = No_of_Bacteria-1;
tempDie=tempDie+1;
end
end
Generation(2) = tempGen;
TotalBacteria(2) = No_of_Bacteria;
%%%%%%%%%%%%% Generation-1 %%%%%%%%%%%
%%%%%%%%%%%%% Generation-2 %%%%%%%%%%%
BacteriaGrowth(3) = TotalBacteria(2);
No_of_Bacteria = TotalBacteria(2);
tempGen=0;
tempDie=0;
for j=1:No_of_Bacteria
tempProb = rand;
if (tempProb >= SurvivalProb),
No_of_Bacteria = No_of_Bacteria+2;
tempGen=tempGen+2;
else
No_of_Bacteria = No_of_Bacteria-1;
tempDie=tempDie+1;
end
end
Generation(3) = tempGen;
TotalBacteria(3) = No_of_Bacteria;
%%%%%%%%%%%%% Generation-2 %%%%%%%%%%%
figure,
plot(Generation); title('------------- Bacteria Growth Vs Generation No. ---->'); xlabel('---- Generation No. ---->'); ylabel('----- No. of Bacteria ---->');
plot(TotalBacteria); title('------------- Total No. of Bacteria Vs Generation No. ---->'); xlabel('---- Generation No. ---->'); ylabel('----- No. of Bacteria ---->');
Generation
TotalBacteria
%%%%%% No. of Bacteria in each generations %%%%%%%%%%%%%
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.