Answered step by step
Verified Expert Solution
Question
1 Approved Answer
All the MMCQ Validation tests failed. They have to be passed. Please fix the issues on the MATLAB Code: Ws =10.00 Fail Wq = 0.000
All the MMCQ Validation tests failed. They have to be passed. Please fix the issues on the MATLAB Code: Ws =10.00 Fail Wq = 0.000 c_util = - 10015.010 FAIL p_drop = 0.000 Please help me to fix the MATLAB Code % Run this test case to check your code % Parameters c = 2; % Number of servers lambda = 20; % Average Arrival Rate mu = 0.1; % Service rate Nwait = 15; rho = lambda / (c * mu); % Compute the Erlang B formula to calculate the probability of blocking p_block = erlangb(c, rho); % Call the MMCQ function with the given parameters [Ws, Wq, c_util, p_drop, p_state] = MMCQ(lambda, mu, c, Nwait); % 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, 0.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.00272) < 0.005 fprintf('p_drop = %8.5f PASS ', p_drop); else fprintf('p_drop = %8.5f FAIL ', p_drop); end fprintf('p_state: %s ', p_state); fprintf('sum(p_state): %f ', sum(p_state)); fprintf('p_drop: %s ', p_drop); % Extra Tests: p_state % p_state should have 10 probabilities disp(['The probability of being in state ', ' is ', num2str(p_state)]); % Check that the probabilities sum 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 function [Ws, Wq, c_util, p_drop, p_state] = MMCQ(lambda, mu, c, Nwait) rho = lambda / (c * mu); % Calculate the utilization factor c_bar = rho * (1 + (c * rho)^c / factorial(c) / (1 - rho)); c_util = c_bar / c; % 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; p_state = zeros(1, Nwait + 1); pN = p_state(Nwait + 1); % Calculate lambda_loss and lambda_eff lambda_loss = lambda * pN; lambda_eff = lambda - lambda_loss; % Calculate Lq (average number of customers in the queue) Lq = sum((0:Nwait) .* p_state); % Calculate Ls (average number of customers in the system) Ls = Lq + lambda_eff / mu; % Calculate p_drop (probability of a customer being dropped) p_drop = pN / (1 + pN); % Calculate pN (probability of having N customers in the system) 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 end % Calculate Ws and Wq Ws = Ls / lambda_eff; Wq = Lq / lambda_eff; end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started