필터 지우기
필터 지우기

Integrate over range of a vector using trapz

조회 수: 5 (최근 30일)
Konstantin
Konstantin 2016년 9월 12일
답변: Jordan Ross 2016년 9월 19일
I have a random lognormally distributed variable shock defined over the range:
shock = 0.5:0.001:2;
rb = 1.0204;
sigma = 0.174;
mu = 1;
Then I calculate a function of it:
LossF = @(LTV,shock) rb*(1 - (mu*(1 - normcdf((0.5*(sigma)^2 -log(LTV'*shock))/sigma, 0, 1))./(LTV'*shock) + 1 - logncdf(LTV'*shock, -0.5*(sigma^2), sigma))./(mu*(1 - normcdf((0.5*(sigma)^2 -log(LTV'*ones(1,size(shock,2))))/sigma, 0, 1))./(LTV'*ones(1,size(shock,2))) + 1 - logncdf(LTV'*ones(1,size(shock,2)), -0.5*(sigma^2), sigma)) );
Loss = LossF(0.8,shock);
And calculate the pdf of Loss using the theorem for pdf of a function of a random variable:
pdfL = lognpdf(shock, -0.5*(sigma^2), sigma).*gradient(shock);
Checks:
When I integrate over the pdf of shock I get 1 as it should be:
trapz(shock,lognpdf(shock, -0.5*(sigma^2), sigma))
However when I integrate over the pdf of Loss i get:
trapz(Loss,pdfL) = 1.4236e-04
However2 integrating over the pdf of Loss without range gives 1:
trapz(pdfL) = 1
When I plot Loss and pdfL it seems that the range of Loss(1) and Loss(end) cover the entire range of the pdf function. How does an integral over that range return such a small number: 1.4236e-04. When integral over the same function without first argument returns 1?

채택된 답변

Jordan Ross
Jordan Ross 2016년 9월 19일
Hello Konstantin,
The reason that you receive such a small number when you execute the following code:
trapz(Loss,pdfL)
is that the range "Loss" does not correspond to the PDF "pdfL". When you define "pdfL" you pass "shock" as the parameter 'X' so therefore the return value "pdfL" corresponds to the values of "shock". See the documentation of "lognpdf" for more information: http://www.mathworks.com/help/stats/lognpdf.html
Furthermore, when you plot "pdfL" as follows:
plot(pdfL)
you see the full curve for the PDF.
When you plot:
plot(Loss,pdfL)
you see that the x-values used do not return the same curve for the PDF.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by