Matlab is giving me a zero answer when there is actually a real non zero answer !!!!
Show older comments
So i noticed my long program give zero when i ever reach iteration number 78 , when i checked what is zeroing my numbers, it was this function
Y = nchoosek(78,4)*((( gamma(3+4)*gamma(60+78-3-4)*gamma(60))/(gamma(3)*gamma(60-3)*gamma(60+78))))
it seems Matlab is calculating the upper first ans assigning it inf and then doing the same for the lower part. then dividing and estimating which inf will win.
How can i stop this !!! This function should return a probability, iteration 77 return a value of 0.124 something !!!
What to do ?
2 Comments
When I run that the upper part is not Inf (just a very large number of the order of 1e302), but the lower part is (I forget which is which in numerator and denominator so upper and lower will do me!) so something divided by infinity is considered to be 0.
I guess you need to get some better bounds on your calculations if you want a more meaningful answer as any maths involving Inf is going to be nonsense unless you are happy with Infinity as being valid.
ibrahim alturki
on 31 Oct 2017
Accepted Answer
More Answers (1)
Walter Roberson
on 31 Oct 2017
n1 = sym(78);
n2 = sym(60);
d1 = sym(4);
d2 = sym(3);
Y = nchoosek(n1, d1)*((( gamma(3+4)*gamma(n1+n2-d2-d1)*gamma(n2))/(gamma(d2)*gamma(n2-d2)*gamma(n1+n2))));
2 Comments
ibrahim alturki
on 1 Nov 2017
Walter Roberson
on 1 Nov 2017
In the above expression, using sym(), the gamma() or factorial() are fully expanded to exact integers for arguments up to 999, and exact multiplication and division are used, leading to an exact rational solution rather than a numeric approximation.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!