normpdf is taking zeros
Mostra commenti meno recenti
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 Commenti
David Hill
il 25 Set 2021
normpdf(-38);%this reports 1.097221051994971e-314, you want smaller than this?
hey yo
il 25 Set 2021
Anjali
il 5 Mag 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.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su MATLAB Support for MinGW-w64 C/C++ Compiler in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
