Returning NaN after mean calculation?

Just wondring why my code is returning NaN when I use the mean fucntion? My numbers are not that big i have scaled back the number of runs from 1000 to 10 but still no change. I'm confused
clear all
close all
clc
% set up variables
no_of_calls = 60;
no_of_runs = 10;
CallTime = [];
CallLength =[];
n = ones(1,no_of_calls).*42;
E_1 = zeros(no_of_runs, no_of_calls);
call_timeDIST= makedist('Uniform');
call_lengthDIST = makedist('Poisson','lambda',3);
CallLength = zeros(no_of_runs,no_of_calls);
for i = 1:no_of_calls
for j = 1:no_of_runs
% Create distribution for calls in time
CallTime(j) = random(call_timeDIST);
% Create distribution for call length
CallLength(j,i) = random(call_lengthDIST);
% calculate A0
A_0 = 600.*(CallLength./60);
% calculate E_1 using Erlings-B Formula
E_1(j,i) = part_2(A_0(j,i), n(i));
end
% Find Mean for number of iterations
GOS = mean(E_1,2);
end
Unrecognized function or variable 'part_2'.
CT = sort(CallTime)';
plot(CT, GOS)

2 Comments

We don't know what "part_2" does with A_0(j,i) and n(i).
function E_1 = part_2(A_0,n)
for i = 1:n
S(i) = (A_0^i)/factorial(i); %% Create vector of
% values to be summed
% to create denominator
dnom = cumsum(S); %% Create denominator
end
for n = 1:n
num1(n) = ((A_0^n)/factorial(n)); %% loop through values
% values of n for numerator
% createing vector of numerators
% for specified A0
end
for n = 1:n
E_1 = num1(n)./dnom(n); % Complete formula for answer
end

Sign in to comment.

 Accepted Answer

function E_1 = part_2(A_0,n)
n=1:n;
S = (A_0.^n)./factorial(n);
dnom = cumsum(S);
E_1 = S./dnom;
end

2 Comments

Unable to perform assignment because the size of the left side is 1-by-1 and the
size of the right side is 1-by-42.
Error in EE4101_Cormac_Carr_Part2 (line 26)
E_1(j,i) = matlab(A_0(j,i), n(i));
Got it working thanks for your help

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!