User Tools

Site Tools


gibson:teaching:fall-2012:math445:sickcat2.m

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

<code> % Suppose my cat gets sick one day out of seven. % How likely is she to get sick two days in one week? % This script is a compact but tricky solution. Ntrials = 10000; % number of trials probsick = 1/7; % prob of being sick on a given day count = 0; % number of weeks with two sick days probsick_vector = probsick*ones(7,1); % auxiliary variable for n = 1:Ntrials; % sum(rand(7,1) < probsick_vector) counts the number of sick % days in a given week. If that sum is 2, increment the count count = count + (sum(rand(7,1) < probsick_vector) == 2); end prob = count/Ntrials; fprintf('Prob of two sick days per week is %f\n', prob); </code>

gibson/teaching/fall-2012/math445/sickcat2.m.1348778716.txt.gz · Last modified: 2012/09/27 13:45 by gibson