normpdf is taking zeros
Show older comments
Hello, I am using the normpdf command to evaluate a function in MATLAB. When the argument of normpdf is too small, MATLAB reports a zero. Is is possible to get the exact value of normpdf instead of 0?
4 Comments
David Hill
on 25 Sep 2021
normpdf(-38);%this reports 1.097221051994971e-314, you want smaller than this?
hey yo
on 25 Sep 2021
Anjali
on 5 May 2024
Hey, I'm stuck on similar problem and not able to decode it, how did you proceed further
I showed what you can do in my answer. If you will form the product of numbers, AND some of those numbers in the product are hugely large, you can always take the logs of each term in the product, then add the logs. Then exponentiate the sum at the end.
And you should see that the log of a normal PDF is trivially easy to compute. For example, even without using syms, we can do that:
mu = 0;
sig = 1;
x = -77;
logp = -(x-mu).^2/sig^2/2 - log(sig) - log(sqrt(2*pi))
Of course, that is a pretty large negative number. But now you can work with the logs of those terms. In the end, the result will still probably be numerical garbage, and still very likely result in an underflow, becaluse logp is such a negative result. But unless you are willing to work entirely in terms of higher precision numbers, this is the best you can do.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Support for MinGW-w64 C/C++ Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!