Poisson distribution-for loop not working

1 view (last 30 days)
Arosh Perera
Arosh Perera on 12 Mar 2019
Answered: John D'Errico on 12 Mar 2019
I'm developing a mathematical model and i have to calculate some probabilities like this,
p_C=0;
for i=0:x(1)-1
for a=x(2):x(1)+x(2)-i-1
m=sum(poisspdf(i,L_1*x(3))*sum(poisspdf(a,L_2*x(3))));
p_C=p_C+m;
end
p_C;
end
p_C;
But, all the time it gives 0. Why is that? Is there any way to calculate this?

Answers (1)

John D'Errico
John D'Errico on 12 Mar 2019
It is impossible to know. What is x(1)? What is x(2)? I would suggest that you look at those numbers. For example, suppose x(1) is less than 1? What is this? Look at the look that creates i.
0:-.5
ans =
1×0 empty double row vector
So, if x(1) is less than 1, then the outer loop will not execute at all. In that case, p_C will never change from 0.
But without knowing what x is, we cannot tell you anything.
Beyond that, we are not told what values L_1, L_2, and x(3) are.
So the answer is simple. Step through your code. Look at the variables. Consider what happens, depending on the values of those variables.
Or, you can actually give us a hint as to what all of those numbers are. Then we could try to help you more than I have done. But really, the most efficient way is for you to learn to debug your code, rather than waiting for someone to do this for you.

Community Treasure Hunt

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

Start Hunting!