nested for loops and plotting

5 views (last 30 days)
hi there!!I need a graph something like below for the values 400 500 600 700 but I cant find where my problem is.Please help!!
proportion2 gives 4 values
when process comes to plotting it runs and runs for too long and there is nothing on the screen.
N=int32((0.25)*(2.575/0.01)^2)
C=600
p=0.301
d=0.15 %Geometric distribution with parameter%
beta=10
lambda=3
TotalTime=zeros(N,1);
hold on
for C=[400 500 600 700]
for k=1:N %N is 16577%
X1=sum(rand(C,1)<p);
Y1=ceil(log(1-rand(X1,1))/log(1-d));
TotalTasks2=sum(Y1);
T2=sum(-1/lambda * log(rand(beta,TotalTasks2)));
TotalTime(k)=sum(T2);
end
proportion2=mean(TotalTime<3600)
plot(TotalTime/60,proportion2 )
end
  2 Comments
Walter Roberson
Walter Roberson on 20 Jun 2020
N is 16577, and we know that p is 0.3 from one of your previous questions, but what is d and what is lambda and what is beta ?
fatih goncagül
fatih goncagül on 20 Jun 2020
Thanks a lot for checking out!I edited it.Can you have a look again?

Sign in to comment.

Accepted Answer

fatih goncagül
fatih goncagül on 21 Jun 2020
close all;
clear;
figure;
n=100000;
p=.301;
q=.15;
beta=10;
lambda=3;
timeofprobabilityestimation=60;
interval=.1;
for c=[400 500 600 700]
i=1;
pest=[];
totaltime=zeros(n,1);
for k=1:n
x=sum(rand(c,1)<p);
y=ceil(log(1-rand(x,1))/log(1-q));
totaltasks=sum(y);
t=sum(-1/lambda * log(rand(beta,totaltasks)));
totaltime(k)=sum(t);
end
for timeval=0:60*interval:60*100
pest(i)=mean(totaltime<timeval);
i=i+1;
end
timeval=0:interval:100;
plot(timeval,pest)
hold on;
end
legend('400', '500' ,'600', '700')
title('Total time vs probability')
xlabel('total time less than h')
ylabel('probability')

More Answers (1)

Walter Roberson
Walter Roberson on 21 Jun 2020
total time is a vector. mean of a vector is a scalar. You are plotting with a bunch of different x values and a single y value.. note that your total time values are not sorted so you are not even drawing some kind of bar showing maximum and minimum.

Categories

Find more on Performance and Memory in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!