Peak in probability distribution moves in normpdf when changing lower bound for input vector

2 views (last 30 days)
I am trying to compare some data with a computed normal approximation to the dataset. I computed the sample mean and standard deviation the normal ways (mean and std)', I've come up with 40K and 6K (to 1 SF). When I try to plot this distribution using a simple statement:
plot(normpdf(10e3:70e3,40e3,6e3))
It shows the peak in the probability distribution as 30K! When I use a different lower bound for the vector to plot, it moves the probability peak further (e.g., if I start at 20K, the peak moves to 20K).
It appears that the peak in the distribution is appearing at $MEAN- /$LOWER_BOUND, as when I set the lower bound to zero, I get the expected behavior of a normal PDF centered at 40K. The standard deviation of 6K appears to be correctly used in all cases.
Similar behavior is manifested when using a negative lower bound: using the below command changes the peak in the probability displayed to 60K
plot(normpdf(-20e3:70e3,40e3,6e3))

Accepted Answer

David Goodmanson
David Goodmanson on 14 Apr 2025
Edited: David Goodmanson on 14 Apr 2025
Hi Chris, try
x = 10e3:70e3;
plot(x,normpdf(x,40e3,6e3))
The problem occurs because if you create y = f(x) and use plot(y), the plot command has no way of knowing what the x array might have been. Without an explicit x input, the x axis is taken to be the y array indices 1:length(y).
  1 Comment
Chris Ostrom
Chris Ostrom on 14 Apr 2025
That makes a lot of sense, I assumed that the information somehow was transmitted between the functions. I can confirm that plotting the array and NORMPDF(array) does indeed provide the expected results.
Thanks!

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!