Hi all!
I have a brief question. I am trying to obtain the area under a PDF curve. Concretely, the PDF follows a Lognormal distribution with paremeter mu=0 and sigma=0.9.
zmax=10;
gridz=600;
m=0;
sig=0.9;
z=logspace(0,log(zmax)/log(10),gridz);
g=lognpdf(z,m,sig);
trapz(z,g)
However, the value I obtain is equal to 0.49, far from 1. Any advise please?
Thanks in advanced,
Ibai

5 commentaires

Torsten
Torsten le 1 Mar 2022
z consists of 600 times the same value, namely 1...
Ibai Ostolozaga Falcon
Ibai Ostolozaga Falcon le 2 Mar 2022
Sorry!
There was a typo in the code that I posted. I have just edited. Once I have changed it, any advise please?
Torsten
Torsten le 2 Mar 2022
Modifié(e) : Torsten le 2 Mar 2022
The first element in the z-vector is z(1)=1.
To get trapz(z,g)=1, you will have to start with z(1) = small value > 0.
So
z = linspace(1e-8,10,gridz)
instead of
z=logspace(0,log(zmax)/log(10),gridz)
should work.
Ibai Ostolozaga Falcon
Ibai Ostolozaga Falcon le 3 Mar 2022
Hi Torsten,
Thank you for your answer! Using linspace and starting at 0, gives me back a value very close to one.
However, I would like to ask why when z(1)=0 gives back a value close to one and when I use z(1)=1 not. That is, when I am building the pdf I am giving to Matlab a grid with 600 points that goes from 1 to 10.
Thank you in advanced.
Torsten
Torsten le 3 Mar 2022
Modifié(e) : Torsten le 3 Mar 2022
However, I would like to ask why when z(1)=0 gives back a value close to one and when I use z(1)=1 not.
The area under the PDF curve between 0 and 1 is 0.5.

Connectez-vous pour commenter.

Réponses (1)

Chunru
Chunru le 3 Mar 2022

0 votes

For pdf that matlab supports, you can use cdf function to find the area under pdf. For your case
zmax=10;
m=0;
sig=0.9;
logncdf(zmax, m, sig)
ans = 0.9947

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by