Question: Can you please help me to fix the MATLAB Code to fix the calculation of p _ state which is incorrect as it does not

Can you please help me to fix the MATLAB Code to fix the calculation of p_state which is incorrect as it does not computer all p_states which are in the queue and being served ?
The MMCQ Validation failed except c_util and the correct Ws value should be 2.1557.instead of 2.140 as shown the out put below. Thanks
% Define system parameters
lambda =2; % arrival rate
mu =5; % service rate
c =3; % number of servers
Nwait =15; % maximum number of customers in the queue
% Call the MMCQ function with the given parameters
%[Ws, Wq, c_util, p_drop, p_state]= MMCQ(lambda, mu, c, Nwait);
% Run this test case to check your code
[Ws, Wq, c_util, p_drop, p_state]= MMCQ(1,0.5,4,5);
% Define a relative error function
rel_error = @(x,y) abs(x - y)/y;
% Validate the results and print "PASS" or "FAIL" for each metric
% if rel_error(Ws, p_state(1))<0.005
% fprintf('Ws %6.3f PASS
', Ws);
% else
% fprintf('Ws %6.3f FAIL
', Ws);
% end
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
', c_util);
else
fprintf('c_util %6.3f FAIL
', c_util);
end
if rel_error(p_drop, 0.00283)<0.005
fprintf('p_drop %8.5f PASS
', p_drop);
else
fprintf('p_drop %8.5f FAIL
', p_drop);
end
fprintf('p_state %s
', num2str(p_state));
% Extra Tests
% p_state should have Nwait+1 probabilities
if rel_error(sum(p_state),1)<0.005
disp('The probabilities sum to 1. Test PASSED');
else
disp('The probabilities do not sum to 1. Test FAILED.');
end
function [Ws, Wq, c_util, p_drop, p_state]= MMCQ(lambda, mu, c, Nwait)
rho = lambda /(c * mu);
p0_denom = sum((c * rho).^(0:(c -1))/ factorial(0:(c -1)))+(c * rho)^c / factorial(c)/(1- rho);
p0=1/ p0_denom;
p_state = zeros(1, Nwait +1);
p_state(1)= p0;
for i =1:Nwait
ci = min(i, c);
if i <= c
p_state(i +1)= ci / c * p_state(i)* rho / factorial(i);
else
p_state(i +1)= c^ci / factorial(ci)* p_state(i)* rho^i / factorial(c);
end
end
p_state = p_state / sum(p_state);
% pN = p_state(Nwait +1);
pN = p_state(Nwait);
lambda_loss = lambda * pN;
lambda_eff = lambda - lambda_loss;
Lq = sum((0:Nwait).* p_state);
Ls = Lq + lambda_eff / mu;
c_bar = Ls - Lq;
c_util = c_bar / c;
p_drop = pN;
Ws = Ls / lambda_eff;
Wq = Lq / lambda_eff;
End
Ws =2.140 FAIL
Wq 0.140 FAIL
c_util 0.500 PASS
p_drop 0.00002 FAIL
p_state 0.875950.109490.0136870.000855421.7821e-052.4752e-07
The probabilities sum to 1. Test PASSED

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!