made first impressions on lab_2
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
number_of_senders = 4;
|
||||||
|
number_of_timeslots = 1000;
|
||||||
|
access_probability = 0:0.01:1;
|
||||||
|
|
||||||
|
access_probability_length = length(access_probability);
|
||||||
|
|
||||||
|
sender_rands = zeros(number_of_senders);
|
||||||
|
% | slot1 | slot
|
||||||
|
% prob1 |
|
||||||
|
result = zeros(access_probability_length, number_of_timeslots);
|
||||||
|
|
||||||
|
% simulate all time slots on each probability
|
||||||
|
for probability_idx = 1 : access_probability_length
|
||||||
|
|
||||||
|
current_result = zeros(access_probability_length);
|
||||||
|
probability = access_probability(probability_idx);
|
||||||
|
|
||||||
|
for i = 1 : number_of_timeslots
|
||||||
|
% generate random sender accesses
|
||||||
|
for j = 1 : number_of_senders
|
||||||
|
sender_rands(j) = rand();
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
result(probability_idx, :) = current_result;
|
||||||
|
end
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
number_of_senders = 4;
|
||||||
|
number_of_timeslots = 1000;
|
||||||
|
access_probability = 0:0.01:1;
|
||||||
|
|
||||||
|
access_probability_length = length(access_probability);
|
||||||
|
|
||||||
|
sender_access = zeros(number_of_senders);
|
||||||
|
|
||||||
|
% | slot1 | slot2 | ...
|
||||||
|
% prob1 | | | ...
|
||||||
|
% prob2 | | | ...
|
||||||
|
% ... | ... | ... | ...
|
||||||
|
result = zeros(access_probability_length, number_of_timeslots);
|
||||||
|
|
||||||
|
% simulate all time slots on each probability
|
||||||
|
for probability_idx = 1 : access_probability_length
|
||||||
|
|
||||||
|
current_result = zeros(1, number_of_timeslots);
|
||||||
|
probability = access_probability(probability_idx);
|
||||||
|
|
||||||
|
for time_slot = 1 : number_of_timeslots
|
||||||
|
% generate random sender accesses by probability
|
||||||
|
sender_access = zeros(1, number_of_senders);
|
||||||
|
for sender = 1 : number_of_senders
|
||||||
|
if rand() < access_probability(probability_idx)
|
||||||
|
sender_access(1, sender) = 1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
current_result(1, time_slot) = sum(sender_access(1, :)) == 1;
|
||||||
|
end
|
||||||
|
|
||||||
|
result(probability_idx, :) = current_result;
|
||||||
|
end
|
||||||
|
|
||||||
|
disp(result(floor(access_probability_length / 2), 1:100))
|
||||||
Reference in New Issue
Block a user