Pregunta

I have trouble with the probability density function (p.d.f) of a log-normal distribution. I really need your help. As defined by wikipedia: http://en.wikipedia.org/wiki/Log-normal_distribution#Probability_density_function

The probability density function of a log-normal distribution is:

pdf of log-normal distribution

My problem is, how to define x variable in MATLAB? Thanks for your help!

¿Fue útil?

Solución

If you have the Stats toolbox, you can just use lognpdf:

y = lognpdf(x,mu,sigma);

Though this is a very simple function - fully vectorized, it's effectively just:

y = exp(-0.5*((log(x)-mu)./sigma).^2)./(x.*sqrt(2*pi).*sigma);

But you may want to check that x > 0 and sig > 0. To create this plot on the Wikipedia article that you cited, you can do:

mu = 0;
sigma = [1;0.5;0.25];
x = 0:0.01:3;
y = lognpdf([x;x;x],mu,sigma(:,ones(1,length(x))));
figure; plot(x,y);

When your question asks about defining x, maybe you're actually looking for log-normally distributed random variables, i.e., you want to sample randomly from the log-normal PDF/distribution? In that case you can use lognrnd:

r = lognrnd(mu,sigma);

Otros consejos

I'm confused, like you can do this in a one-liner,

fun = @(x,mu,sigma) (1./(x*sigma*sqrt(2*pi))).*exp( -(power((log(x)-mu),2))/(2*power(sigma,2)))

x is any value that satisfies x > 0, the pdf tells you via Wikipedia

In probability theory, a probability density function (pdf), or density of a continuous random variable, is a function that describes the relative likelihood for this random variable to take on a given value.

So any value x given to the log-normal pdf tells you tel relative likelihood that a random variable could be that value.

Consider this toy example:

mu = 1;
sigma = 10;
x = logspace(-2,0,10);
plot( x, fun(x,1,10) )

log plot

From this plot as x gets closer to zero, it's relative likelihood of actually taking on that value increases. DISCLAIMER I just threw that function together, it needs to be checked for accuracy, the preceding was for illustration only.

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