1+1

댓글 수: 1

John D'Errico
John D'Errico 2015년 3월 29일
Please use the question for your questions, rather than posting additional information as answers. And use the comment link to add comments. Finally, please make your code readable, instead of all strung out in one line. Learn to use the "{} Code" button.

댓글을 달려면 로그인하십시오.

 채택된 답변

the cyclist
the cyclist 2015년 3월 29일

0 개 추천

Because this is homework -- thank you for clearly indicating that fact -- I don't want to just give you the answer. But here are a few hints:
  • You should very carefully read the documentation for poissrnd.
  • The documentation gives a very clear example of how to generate 10 realizations of a poisson distribution, which can adapt to give 100 or 1000 realizations, as your assignment requires.
  • You will not need to use a for loop to do that.
  • The output of that command will give a certain number of X=0, some of X=1, etc., and that is how you will estimate the probability of getting each of those values.

댓글 수: 9

m
m 2015년 3월 30일
how I will write the x=0,x=1,.... in the program
the cyclist
the cyclist 2015년 3월 30일
Why did you delete your question?
m
m 2015년 3월 30일
by mistake sorry
After you run poissrnd, you will have your output vector with the values of X. Maybe it looks like
X = [0 0 1 0 2 0 1 2 3 ...
You can use the histcounts command to get the counts of each individual value. Again, I recommend a careful reading of the documentation, to ensure that you use the syntax correctly, and get the result you expect.
Noor Yusuf
Noor Yusuf 2015년 4월 16일
Hello, thank you for your help! I just have a question regarding finding the probability of X=0, X=1, X=2... First I used a function to generate 100 random variables. However, the function poisspdf(X,2) for lambda =2 is not applicable to find the probability in this case. I am confused whether I shall use the function nnz(X==) to find the counts of each individule value or not. I read about the histcounts function but I still did not get how to use it actually. There is no other function that I can use?
Using
for i = 0:3
NX(i) = nnz(X==i) % Loop over the values
end
in a for loop will get you what you want. It is slower than a vectorized method, but it will work and you understand it, so that may be your best approach.
But, you can also get all the counts by using the older command hist
NX = hist(X,[0:3])
or the newer command histcounts
NX = histcounts(X,[0:3 Inf])
The syntax is a bit different between hist and histcounts, because the latter command defines the bins by the locations of the edges, rather than the centers.
Noor Yusuf
Noor Yusuf 2015년 4월 16일
Thanks it works now ! then how I will use it to find the probabilities. poisspdf() function is not applicable in this case right?
the cyclist
the cyclist 2015년 4월 16일
This is obviously the final step of your homework. I think you can do it.
Hint: You've generated 100 realizations of the poisson distribution, and you know how many times you got X=0, X=1, etc. So, how do you calculate the probability of X=0, X=1, etc from that?
Noor Yusuf
Noor Yusuf 2015년 4월 17일
Thank you. I thought I have to use a function to calculate the probability.I really appreciate your help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

질문:

m
m
2015년 3월 29일

편집:

m
m
2015년 5월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by