Finished lab_2
This commit is contained in:
+11
-8
@@ -6,11 +6,8 @@ access_probability_length = length(access_probability);
|
||||
|
||||
sender_access = zeros(number_of_senders);
|
||||
|
||||
% | slot1 | slot2 | ...
|
||||
% prob1 | | | ...
|
||||
% prob2 | | | ...
|
||||
% ... | ... | ... | ...
|
||||
result = zeros(access_probability_length, number_of_timeslots);
|
||||
simulated_throughput = zeros(1, access_probability_length);
|
||||
estimated_throughput = zeros(1, access_probability_length);
|
||||
|
||||
% simulate all time slots on each probability
|
||||
for probability_idx = 1 : access_probability_length
|
||||
@@ -29,8 +26,14 @@ for probability_idx = 1 : access_probability_length
|
||||
|
||||
current_result(1, time_slot) = sum(sender_access(1, :)) == 1;
|
||||
end
|
||||
|
||||
result(probability_idx, :) = current_result;
|
||||
|
||||
simulated_throughput(probability_idx) = mean(current_result);
|
||||
estimated_throughput(probability_idx) = number_of_senders * probability * (1 - probability)^(number_of_senders - 1);
|
||||
end
|
||||
|
||||
disp(result(floor(access_probability_length / 2), 1:100))
|
||||
plot(access_probability, estimated_throughput)
|
||||
hold on
|
||||
plot(access_probability, simulated_throughput)
|
||||
legend("theoretical", "simulation")
|
||||
xlabel("access probability")
|
||||
ylabel("throughput")
|
||||
Reference in New Issue
Block a user