1
votes

This is the probability density function:

Probability Density Function

Code:

f=exp(-(((log(x)-log(100)-(.1((.15)^2)/2))^2))/(2*.15^2))/(x(.15)*sqrt(2*pi));

plot(f);

I can't seem to plot this lognormal distribution in Matlab. I am trying to find what percent of this graph is above 100, and don't know how to do that step in code.

2
@excaza I added the function in the original questionpatriotsredsox37

2 Answers

0
votes

Maybe you'd want to give x some values and define f(x) as an ananymous function

f=@(x) exp(-(((log(x)-log(100)-(.1.*((.15).^2)./2)).^2))./(2*.15^2))./(x*.15*sqrt(2*pi));

x = 50:150
plot(x, f(x))

EDIT: Area of the density function for x>=100:

>> quad(f,100,Inf)
ans =  0.50299

enter image description here

0
votes

MATLAB has made this process even easier with the makedist(), pdf(), and cdf() functions**.

In the example below, the area above 25 is 0.0638 (6.38%).

pd = makedist('Lognormal',2,.8);     % Create Lognormal probability distribution object

X = (0:.01:50)';
figure, hold on, box on
p = plot(X,pdf(pd,X),'b-','DisplayName','A')      % Uses `pdf` function on the object
%legend('show')
title('Lognormal Distribution (\mu = 2, \sigma = 0.8)')
set(p,'LineWidth',2.0)

% Percent above 25
1-cdf(pd,25)        % = 0.0638    % Uses `cdf` function on the object

PDF of Lognormal

** Probability distribution objects introduced in MATLAB 2013a.