Problem in using the integral function to compute a partial expectation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
Vimal Rathod
el 3 de Dic. de 2020
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.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!