Reputation: 59
I need to calculate the density of 50 in a standard normal distribution, actually, the result will return to 0 by pdf('norm',50,0,1)
, then I try to display the logarithm of it,it doesn't work with log(pdf('norm',50,0,1))
. In R, we can do like dnorm(50,log = TRUE)
, any similar function in MATLAB? I did not find it. thanks
Upvotes: 1
Views: 63
Reputation: 112679
If you compute the pdf evaluated at 50, you get 0 because of finite precision (spefically, the result is less than realmin
). You should compute the logarithm directly. From the definition, the logarithm of a standard normal pdf evaluated at 50 is
>> format long %// to show more decimals
>> -50^2/2 - .5*log(2*pi)
ans =
-1.250918938533205e+003
Upvotes: 2