├── README.md ├── biased_coin.m ├── birthday.m ├── my_gaussian.m ├── random_integers.csv └── test_biased_coin.m /README.md: -------------------------------------------------------------------------------- 1 | # matlab-probability-class 2 | Resources and Materials for MATLAB Probability class 3 | -------------------------------------------------------------------------------- /biased_coin.m: -------------------------------------------------------------------------------- 1 | function [ face ] = biased_coin( p_heads ) 2 | 3 | if rand < p_heads 4 | face = 'h'; 5 | else 6 | face = 't'; 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /birthday.m: -------------------------------------------------------------------------------- 1 | function [ A ] = birthday( n ) 2 | 3 | A = ones(n, 1); 4 | p = 1; 5 | for i=1:n 6 | A(i) = 1 - p; 7 | p = p * (365 - i)/365; 8 | end 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /my_gaussian.m: -------------------------------------------------------------------------------- 1 | function [ X, f ] = my_gaussian( mu, sigma_sq, min_x, max_x, n) 2 | 3 | 4 | f = zeros(n, 1); 5 | X = zeros(n, 1); 6 | x = min_x; 7 | dx = (max_x - min_x) / n; 8 | for i = 1:n 9 | X(i) = x; 10 | f(i) = 1 / sqrt(2*pi*sigma_sq) * exp( -(x - mu)^2 / (2*sigma_sq) ); 11 | x = x + dx; 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /random_integers.csv: -------------------------------------------------------------------------------- 1 | 3 2 | 4 3 | -4 4 | 5 5 | 1 6 | -4 7 | -2 8 | 1 9 | 5 10 | 5 11 | -4 12 | 5 13 | 5 14 | 0 15 | 3 16 | -4 17 | -1 18 | 5 19 | 3 20 | 5 21 | 2 22 | -5 23 | 4 24 | 5 25 | 2 26 | 3 27 | 3 28 | -1 29 | 2 30 | -4 31 | 2 32 | -5 33 | -2 34 | -5 35 | -4 36 | 4 37 | 2 38 | -2 39 | 5 40 | -5 41 | -1 42 | -1 43 | 3 44 | 3 45 | -3 46 | 0 47 | -1 48 | 2 49 | 2 50 | 3 51 | -2 52 | 2 53 | 2 54 | -4 55 | -4 56 | 0 57 | 5 58 | -2 59 | 1 60 | -3 61 | 3 62 | -3 63 | 0 64 | 2 65 | 4 66 | 5 67 | 1 68 | -4 69 | -4 70 | -3 71 | 4 72 | -3 73 | 3 74 | -3 75 | 5 76 | -2 77 | -3 78 | -3 79 | 1 80 | 0 81 | -2 82 | 4 83 | 1 84 | 1 85 | 5 86 | -2 87 | 3 88 | 3 89 | -1 90 | 1 91 | -5 92 | -5 93 | 0 94 | 3 95 | 5 96 | -4 97 | 1 98 | 0 99 | -5 100 | -2 101 | -------------------------------------------------------------------------------- /test_biased_coin.m: -------------------------------------------------------------------------------- 1 | function test_biased_coin( p_heads, n ) 2 | 3 | A = zeros(n,1); 4 | for i=1:n 5 | A(i) = biased_coin(p_heads); 6 | end 7 | hist(A); 8 | end 9 | 10 | --------------------------------------------------------------------------------