This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/simulations/code/probability.m

7 lines
296 B
Mathematica

n = 20; % number of coin flips
P = 0.6; % probability of head
u = rand(n, 1); % n random numbers between 0 and 1
heads = u < P; % true if head showed up
nheads = sum(heads); % number of heads
fprintf('Of %d coin flips, %d heads showed up.\n', n, nheads);