zeros populating most of my output vector

2 visualizaciones (últimos 30 días)
Cormac Carr
Cormac Carr el 9 de Nov. de 2022
Respondida: David Hill el 10 de Nov. de 2022
I am trying to iterate over a changing variable in a vector so that I use said variable in a function. In this program I want to keep my output between 0.01 and 0.008. To achieve this I have to vary another different variable within the script using if statments. My functions are all working correctly so i am just wondering where i am going wrong in my process?
clear all
close all
clc
no_of_calls = [6 3 2 2 5 29 343 548 535 500 535 593 600 583 571 553 458 316 206 123 64 28 13]; %init no of calls
no_of_runs = 1;
no_of_channels = 46;
for i = 1:23
GOS = zeros(length(no_of_calls(13)), no_of_runs); % create GOS vector
no_of_channels
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels);
while GOS(i) > 0.01
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels);
no_of_channels
if GOS(i) > 0.01
no_of_channels = no_of_channels+1;
if i ~= 1
i = i - 1;
else
i = 1;
end
end
end
while GOS(i) < 0.008
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels);
no_of_channels
if GOS(i) < 0.008
no_of_channels = no_of_channels-1;
if i ~= 1
i = i - 1;
else
i = 1;
end
end
end
end
  5 comentarios
Cormac Carr
Cormac Carr el 10 de Nov. de 2022
Editada: Jan el 10 de Nov. de 2022
function E_1 = part_2(A_0,n)
dnom = zeros(1,n);
num1 = zeros(1,n);
E_1 = zeros(1,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
% disp("NValue")
% n
for n = 1:n
% disp("here")
E_1 = num1(n)./dnom(n); % Complete formula for answer
end
Jan
Jan el 10 de Nov. de 2022
@Cormac Carr: Please use the tools to format code as code. Thanks.
What is the purpose of length(no_of_calls(13)) ? This is 1 in all cases. no_of_calls(13) is a scalar, so its length is 1.
A nicer replacement of:
if i ~= 1
i = i - 1;
else
i = 1;
end
is:
i = max(i - 1, 1);

Iniciar sesión para comentar.

Respuesta aceptada

David Hill
David Hill el 10 de Nov. de 2022
You will start running into problems with higher no_of_calls because the no_of_channels will increase and factorial numbers will become too large.
no_of_calls = [6 3 2 2 5 29];
no_of_runs = 1;
GOS=zeros(1,length(no_of_calls));
no_of_channels=ones(size(GOS))*46;
for i = 1:length(no_of_calls)
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels(i));
while GOS(i)>0.01 || GOS(i)<.008
if GOS(i)>.01
no_of_channels(i) = no_of_channels(i)+1;
else
no_of_channels(i) = no_of_channels(i)-1;
end
GOS(i) = part_3(no_of_calls(i), no_of_runs, no_of_channels(i));
end
end
GOS
GOS = 1×6
0.0100 0.0099 0.0100 0.0100 0.0098 0.0097
no_of_channels
no_of_channels = 1×6
108 104 102 104 108 145
function E_1 = part_2(A_0,n)
r=(1:n)';
num1 = A_0.^r./factorial(r);
dnom = cumsum(num1,1);
E_1 = (num1./dnom)';
end
function GOS = part_3(no_of_calls,no_of_runs,no_of_channels)
n = no_of_channels;
call_lengthDIST = makedist('lognormal','mu',0.69,'sigma',0.44);
CallLength = random(call_lengthDIST,no_of_runs,no_of_calls);
A_0 = no_of_calls*CallLength/60;
E_1 = part_2(A_0, n);
GOS = mean(mean(E_1,2,"omitnan"));
end

Más respuestas (0)

Categorías

Más información sobre Variables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by