Code covered by the BSD License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

Highlights from probOfStreak

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 2.3 KB File ID: #39713 Version: 1.0

probOfStreak

Jeff Evans (view profile)

Calculate the probability of a run or streak of K consecutive successes in N Bernoulli trials.

File Information
Description

% RESULT = PROBOFSTREAK(N, K, P)
% Function to calculate the probability of getting a run or streak of K
% consecutive successes in N Bernoulli trials with probability P. Stated
% otherwise, this calculates the probability of a run or streak of K
% consective heads in N independent coin tosses. N and K are integers where
% N>=0, K>0, and 0<=P<=1.
%
% EXAMPLES:
% Calculate the probability of observing 4 consective heads (successes)
% during 10 coin tosses (trials) using a fair coin (P=0.5):
% result = probOfStreak(10,4,0.5);
%
% Calculate the probability of observing 4 consective heads (successes)
% during 10 coin tosses (trials) using an unfair coin that lands on heads
% 60% of the time (P=0.6):
% result = probOfStreak(10,4,0.6);
%
%
% Algorithm adapted from Javascript code embedded here:
% http://maxgriffin.net/CalcStreaks.shtml
%
% which is an adaptation of the algorithm originally described here: