poissrnd() function HELP PLEASE

1+1

1 comentario

John D'Errico
John D'Errico el 29 de Mzo. de 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.

Iniciar sesión para comentar.

 Respuesta aceptada

the cyclist
the cyclist el 29 de Mzo. de 2015

0 votos

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 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

m
m
el 29 de Mzo. de 2015

Editada:

m
m
el 25 de Mayo de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by