Rename year directories to allow natural ordering
This commit is contained in:
Binary file not shown.
8
year2/semester2/CT248/Assignments/Assignment-02/Lab1.m
Normal file
8
year2/semester2/CT248/Assignments/Assignment-02/Lab1.m
Normal file
@ -0,0 +1,8 @@
|
||||
clear;
|
||||
d = roll_2_dice(10000, 100);
|
||||
[freq, prop] = tabulate_2_dice(d);
|
||||
|
||||
disp(freq);
|
||||
disp(prop);
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
function d = roll_2_dice(N, seed)
|
||||
% function to roll 2 dice and return the combination of each device row in a vector
|
||||
rng(seed);
|
||||
|
||||
% generating two 1 * N vectors of 6 simulated dice rolls and adding them
|
||||
d = randi([1 6], 1, N) + randi([1 6], 1, N);
|
||||
end
|
@ -0,0 +1,14 @@
|
||||
function [freq, prop] = tabulate_2_dice(d)
|
||||
% function to calculate the frequency and proportion of each outcome based on a set of dice throws
|
||||
freq = zeros(1,12);
|
||||
% looping through all the values in d and incrementing the corresponding counter in freq
|
||||
for i = d
|
||||
freq(i) = freq(i) + 1;
|
||||
end
|
||||
|
||||
% looping through each index in prop and calculating the proportion pertaining to that index
|
||||
prop = zeros(1,12);
|
||||
for i = [1:12]
|
||||
prop(i) = freq(i) / sum(freq); % proportion of i is the frequency of i divided by the sum of all freqs
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user