Problem in using the integral function to compute a partial expectation

1 回表示 (過去 30 日間)
Mauricio Tejada
Mauricio Tejada 2020 年 10 月 27 日
回答済み: Vimal Rathod 2020 年 12 月 3 日
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);
end
plot(xx,f1)
title('Using the integral function');
plot(xx,f2);
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?

回答 (1 件)

Vimal Rathod
Vimal Rathod 2020 年 12 月 3 日
Hi,
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!

Translated by