normpdf is taking zeros

7 ビュー (過去 30 日間)
hey yo
hey yo 2021 年 9 月 25 日
コメント済み: hey yo 2021 年 9 月 25 日
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?
  2 件のコメント
David Hill
David Hill 2021 年 9 月 25 日
normpdf(-38);%this reports 1.097221051994971e-314, you want smaller than this?
hey yo
hey yo 2021 年 9 月 25 日
Yes, for example normpdf(-77) returns 0. It is important for me to get the exact number because I multiply this value with other numbers to find the solution to a complicated function. Thank you.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2021 年 9 月 25 日
編集済み: John D'Errico 2021 年 9 月 25 日
No. At least, not in double precision. The "exact" value there is impossible to represent in a double precision number.
The normal pdf at z = -77 should be:
mu = 0;
sig = 1;
x = sym(-77);
p = exp(-(x-mu).^2/sig^2/2)*1/(sig*sqrt(2*sym('pi')))
p = 
vpa(p)
ans = 
Do you understand this is a number with around 1288 zeros after the decimal point, before you see any digits?
As such, the result underflows in double precision. You get ZERO.
realmin
ans = 2.2251e-308
Actually, you can go about as far as -38 or so, before an underflow occurs, with the result as what is known as a denormalized number. But that is around the limit. And even most computations with those numbers at that level will still yield numerical garbage.
normpdf(-38)
ans = 1.0972e-314
You can want what you want, but this is not possible working in double precision. If you are willing to use higher precision tools, such as syms, then yes, you can.
  1 件のコメント
hey yo
hey yo 2021 年 9 月 25 日
Thank you for taking the time to post this reply. It is very valuable.

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by