Pregunta

I am new to statistics. I have a discriminant function:

  g(x) = ln p(x| w)+ lnP(w)

I know it has a normal distribution. I know mü and sigma variables. How can I plot pdf function of it at Matlab?

Here is a conversation: How to draw probability density function in MatLab? however I don't want to use any toolbax of Matlab.

¿Fue útil?

Solución

Use normpdf, or mvnpdf for a multivariate Normal distribution:

mu = 0;
sigma = 1;

xs = [-5:.1:5];
ys = normpdf(xs, mu, sigma);
clf;
plot(xs, ys);

Otros consejos

MATLAB plots vectors of data, so you'll need to make an X-vector, and a Y-vector.

If I had a function, say, x^2, i might do:

x = -1:.01:1; %make the x-vector
y = x.^2; %square x
plot(x,y);

You know the function of the PDF (y = exp(-x.^2./sigma^2).*1/sqrt(2*pi*sigma^2) ), so all you have to do is make the x-vector, and plot away!

Based upon a comment from @kamaci, this question gives a complete answer using @Pete's answer.

To avoid using a MATLAB toolbox, just plot the Normal probability density function (PDF) directly.

mu = 12.5;      % mean
sigma = 3.75;   % standard deviation
fh=@(x) exp(-((x-mu).^2)./(2*(sigma^2)))*(1/sqrt(2*pi*(sigma^2)));  % PDF function
X = 0:.01:25;
p = plot(X,fh(X),'b-')

PDF for Normal(12.5,3.75)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top