poissrnd() function HELP PLEASE

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
the cyclist
the cyclist 2015 年 3 月 30 日
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?
the cyclist
the cyclist 2015 年 4 月 16 日
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