Problem in using the integral function to compute a partial expectation

3 views (last 30 days)
I found a problem in using the integral function to compute a partial expectation for a lognormal distribution. Here is the code:
mu = 2.5652;
sig = 0.0055;
int = @(x) x.*lognpdf(x,mu,sig);
xx = (0.00001:0.1:20)';
f1 = zeros(length(xx),1);
f2 = zeros(length(xx),1);
for i = 1:length(xx)
f1(i) = integral(int,xx(i),Inf);
f2(i) = exp(mu+0.5*sig^2)*logncdf((mu+sig^2-log(xx(i)))/sig);
title('Using the integral function');
title('Using the formula for partial expectation');
Note that for that particular parametrization (with low variance), the partial expetation computed using the integral function drops abruptly to zero for some values of the low bound of the integral. This should no occur. In fact, when computing the partial expetation using the algebraic version (available for the lognomal) that problem does not ocurr. Is there a bug in the integral function?

Answers (1)

Vimal Rathod
Vimal Rathod on 3 Dec 2020
If you change the integral function a bit it will give out the result same as your other plot.
You just have to increase the absolute tolerance property of the function.
% in place of the below line
f1(i) = integral(int,xx(i),Inf);
%use this line
f1(i) = integral(int,xx(i),Inf,'AbsTol',1e-12);
For more information on the properties of integral function refer to the following link.

Community Treasure Hunt

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

Start Hunting!