1+1

1 commentaire

John D'Errico
John D'Errico le 29 Mar 2015
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.

Connectez-vous pour commenter.

 Réponse acceptée

the cyclist
the cyclist le 29 Mar 2015

0 votes

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 commentaires

m
m le 30 Mar 2015
how I will write the x=0,x=1,.... in the program
the cyclist
the cyclist le 30 Mar 2015
Why did you delete your question?
m
m le 30 Mar 2015
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 le 16 Avr 2015
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 le 16 Avr 2015
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 le 16 Avr 2015
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 le 17 Avr 2015
Thank you. I thought I have to use a function to calculate the probability.I really appreciate your help

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by