(* ::Package:: *)
function num_mutants = simulate_inherited _mutation
mut_rate = 3e-6; % probability of mutating at each cell division.
% calibrated to give ~1 mutant
n_ 0 = 1000; % initial number of cells. we assume that none are mutants.
n_divisions = 7; % number of rounds of cell division
cells = zeros(n_ 0,1);
for i=1:n_divisions
cells_temp = cells; % duplicate the cells
mutators = rand(length(cells_temp),1) < mut_rate; % find cells that mutate
cells_temp(mutators | cells_temp) = 1; % cells stay mutated
cells = cat(1,cells,cells_temp); % concatenate mother and daughters
end
num_mutants = sum(cells); % total number of mutants
end