Why my normpdf in not working??

12 views (last 30 days)
Maciej Dawczak
Maciej Dawczak on 21 Jun 2021
Commented: Maciej Dawczak on 25 Jun 2021
Hey, why my normpdf func gives just 0 values?
tempg is 15x1 double :
509.068900000000
516.481400000000
521.696500000000
524.645900000000
524.815600000000
526.077300000000
529.092400000000
532.904900000000
534.609900000000
535.836600000000
555.625600000000
562.575200000000
564.946200000000
570.851500000000
587.199300000000
templm is 15x1 double :
472.553000000000
474.792900000000
477.094100000000
479.618700000000
482.186900000000
496.408900000000
497.575800000000
498.234600000000
498.238900000000
499.949700000000
505.844600000000
508.283500000000
509.053700000000
518.186900000000
519.404700000000
devgd = std(tempgd);
devlm = std(templm);
ygd = normpdf(tempgd)
ylm = normpdf(templm)
subplot(2,1,1)
plot(tempgd,ygd)
%axis([420 620 0 0.02])
subplot(2,1,2)
plot(templm,ylm)
%axis([420 620 0 0.012])

Answers (1)

Steven Lord
Steven Lord on 21 Jun 2021
Let's evaluate the PDF using the formula in the documentation for normpdf at that large x value. I'll choose the smallest value in your two vectors.
x = sym(472.553);
sigma = 1;
mu = 0;
f = (1/(sigma*sqrt(2*pi)))*exp(-(x-mu)^2/(2*sigma^2))
f = 
How small is that?
vpa(f)
ans = 
1.7610343601779488103423727433985e-48491
Yeah, that definitely underflows in double precision.
If you specified the mean (I'm going to estimate it as roughly 495) then the value of the PDF will be quite a bit larger.
sigma = 495;
vf = vpa((1/(sigma*sqrt(2*pi)))*exp(-(x-mu)^2/(2*sigma^2)))
vf = 
0.00051098157878291063575577801991873
  1 Comment
Maciej Dawczak
Maciej Dawczak on 25 Jun 2021
So what to do to get normal distribution of that data?

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!