nested for loops and plotting

5 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2020-6-20
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 2020-6-20
Thanks a lot for checking out!I edited it.Can you have a look again?

请先登录,再进行评论。

采纳的回答

fatih goncagül
fatih goncagül 2020-6-21
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')

更多回答(1 个)

Walter Roberson
Walter Roberson 2020-6-21
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.

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by