Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I added the corrected code p _ state ( i ) = ( c - i ) / ( c - ( c -

I added the corrected code " p_state(i)=(c-i)/(c -(c - i));" but I am still gettting the same error message: % Part 1: Define parameters
c =2; % Number of servers
lambda =2; % Average Arrival Rate per minute
mu =0.1; % Service rate
Nwait =15; % Number of waiting customers
% Part 2: Call the MMCQ function and retrieve results
[Ws, Wq, c_util, p_drop, p_state]= MMCQ(1,0.5,4,5);
% Part 3: Define a relative error function
rel_error = @(x, y) abs(x - y)/ y;
% Part 4: Validate and print results
% p_state(i)=(c-i)/(c -(c - i))
fprintf("Ws: %6.3f
", Ws);
fprintf("Wq: %6.3f
", Wq);
fprintf("c_util: %6.3f
", c_util);
fprintf("p_drop: %8.5f
", p_drop);
fprintf("State Probabilities: ");
for i =1:Nwait +1
i=0:1:10;
p_state(i)=(c-i)/(c -(c - i));
fprintf("p_state(%d): %f,", i, p_state(i));
end
fprintf("
");
% Part 5: Validate and print "PASS" or "FAIL" for each metric
if rel_error(Ws,2.1557)<0.005
fprintf("Ws %6.3f PASS
", Ws);
else
fprintf("Ws %6.3f FAIL
", Ws);
end
if rel_error(Wq,0.1557)<0.005
fprintf("Wq=%6.3f PASS
", Wq);
else
fprintf("Wq=%6.3f FAIL
", Wq);
end
if rel_error(c_util, 0.4986)<0.005
fprintf("c_util %6.3f PASS
", cutil);
else
fprintf("c_util %6.3f FAIL
", c_util);
end
if rel_error(p_drop, 0.00272)<0.005
fprintf("p_drop =%8.5f PASS
", p_drop);
else
fprintf("p_drop =%8.5f FAIL
", p_drop);
end
% Part 6: Corrected p_state initialization
p_state =[-0.010609,-0.021217,-0.021217,-0.014145,-0.0070725,-0.05658,0.0,0.0,0.0,0.01];
% Part 7: Check if the sum of probabilities is close to 1
if abs(sum(p_state)-1)<1e-5
disp("The probabilities sum to 1. Test PASSED.");
else
disp("The probabilities do not sum to 1. Test FAILED.");
end
% Part 8: Assuming 10 states
num_states =10;
fprintf("The probability of being in state %d is %f.
", Nwait, p_state(Nwait +1));
disp("Extra Tests PASSED.");function [Ws, Wq, c_util, p_drop, p_state]= MMCQ(lambda, mu, c, Nwait)
% INPUTS:
% lambda = arrival rate
% mu = service rate
% Nwait = Number of queue elements, not including servers
% c = Number of servers
% OUTPUTS:
% Ws = Average wait in the system
% Wq = Average wait in the queue
% c_util = Average percentage of servers busy
% p_drop = probability the queue is full
% p_state = probability of each state
% INSERT YOUR CODE HERE
% Calculate traffic intensity
rho = lambda /(c * mu);
%% Compute the Erlang B formula to calculate the probability of blocking
% p_block = erlangb(c, rho);
% Calculate the utilization factor
c_util = rho / c;
% Display the result
% Calculate p0(probability of no customers in the system)
p0_denom = sum((c*rho).^(0:(c-1))./ factorial(0:(c-1)));
p0_denom = p0_denom +((c*rho)^c /(factorial(c)*(1-rho)))*(1-(rho^Nwait /(1- rho)));
p0=1/ p0_denom;
fprintf('p0: %.4f
', p0);
% Calculate pN (probability of having N customers in the system)
p_state = zeros(1, Nwait+1);
for i =1:Nwait
if i <= c
p_state(i+1)=(rho^i / factorial(i))* p0;
else
p_state(i+1)=(rho^i /(factorial(c)*(c^(i-c))))* p0;
end
pN = p_state(Nwait+1);
% Calculate p_drop (probability of a customer being dropped)
p_drop = pN;
% Calculate c_util (utilization of the servers)
c_util =(rho^c * p0)/(factorial(c)*(1- rho))*(1- rho^(Nwait - c +1));
% Calculate Wq (average waiting time in the queue)
Wq =((rho^(c+1))* p0)/(factorial(c)*(1- rho/Nwait)^2); % Average waiting time in the queue
% Print the result
fprintf('Average waiting time in the queue (Wq): %.2f', Wq);
% Calculate Ws (average time spent in the system)
Ws = Wq +(1/ mu);
% Print the results
fprintf('p0: %.4f ', p0); fprintf('pN: %.2f', p0);
end
end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

2. Use different groups for different subjects.

Answered: 1 week ago

Question

Define pay ranges. What is the purpose of establishing pay ranges?

Answered: 1 week ago