poissrnd() function HELP PLEASE

1+1

1 Comment

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.

Sign in to comment.

 Accepted Answer

the cyclist
the cyclist on 29 Mar 2015
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 Comments

how I will write the x=0,x=1,.... in the program
Why did you delete your question?
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.
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.
Thanks it works now ! then how I will use it to find the probabilities. poisspdf() function is not applicable in this case right?
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?
Thank you. I thought I have to use a function to calculate the probability.I really appreciate your help

Sign in to comment.

More Answers (0)

Tags

Asked:

m
m
on 29 Mar 2015

Edited:

m
m
on 25 May 2015

Community Treasure Hunt

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

Start Hunting!