Need help initializing variable x and plotting probability density function
显示 更早的评论
Hi, I am currently trying to plot the probability density function (PDF) below.
%Equation and initialized variables
mean = 1930000;
standardDeviation= 64000;
fx = (1/(standardDeviation * sqrt(2 * pi))) * exp(-((x - mean)^2 / (2 * standardDeviation ^ 2)));
In this code, you will notice x is a variable, and is unassigned prior to the code, which obviously presents an error. X is supposed to be a random variable, and the plot of the above function should yield a normally distributed bell curve. I was hoping someone knew how to call x as a randomly assigned variable, as well as plot the PDF to appear as a normal distribution. Thank you in advance!
1 个评论
Theory, plotting, random number generation and much more:
回答(1 个)
Hi Stirling,
To plot the curve
mean = 1930000;
standardDeviation= 64000;
% note theat ^2 is changed to .^2 for elementwise operation
fx = @(x) (1/(standardDeviation * sqrt(2 * pi))) * exp(-((x - mean).^2 / (2 * standardDeviation ^ 2)));
xmin = mean - 3*standardDeviation;
xmax = mean + 3*standardDeviation;
plot(xmin:xmax,fx(xmin:xmax))
Samples of x can be obtained as
xval = normrnd(mean,standardDeviation,1,5)
类别
在 帮助中心 和 File Exchange 中查找有关 Half-Normal Distribution 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
