Integrate over range of a vector using trapz
Show older comments
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?
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!