如何使用 MATLAB 计算对数正态分布的积分

How to calculate the integral of log-normal distribution with MATLAB

我想通过以下方式计算对数正态分布的部分期望:

m = 1;
v = 2;
mu = log((m^2)/sqrt(v+m^2));
sigma = sqrt(log(v/(m^2)+1));

syms x;
d = x*lognpdf(x,mu,sigma);

int(d, x, 0, 10);

但是,MATLAB 表示:

Error using symfun>validateArgNames (line 211) Second input must be a scalar or vector of unique symbolic variables.

Error in symfun (line 45) y.vars = validateArgNames(inputs);

Error in sym/subsasgn (line 771) C = symfun(B,[inds{:}]);

Error in lognpdf (line 36) x(x <= 0) = Inf;

Error in untitled (line 7) d = x*lognpdf(x,mu,sigma);

我什至尝试通过以下方式计算 pdf 的积分:

m = 1;
v = 2;
mu = log((m^2)/sqrt(v+m^2));
sigma = sqrt(log(v/(m^2)+1));

syms x;
d = lognpdf(x,mu,sigma);

int(d, x, 0, 10); 

但是还是有错误,MATLAB说:

Error using symfun>validateArgNames (line 211) Second input must be a scalar or vector of unique symbolic variables.

Error in symfun (line 45) y.vars = validateArgNames(inputs);

Error in sym/subsasgn (line 771) C = symfun(B,[inds{:}]);

Error in lognpdf (line 36) x(x <= 0) = Inf;

Error in untitled (line 7) d = lognpdf(x,mu,sigma);

真不知道怎么回事。 pdf的积分应该是cdf吗?

an answer several months ago类似,统计工具箱目前不支持符号工具箱。 因此,您可以通过硬编码 PDF 本身并集成它来继续:

d = exp(-(log(x)-mu)^2/(2*sigma^2))/(x*sigma*sqrt(2*pi));
int(d, x, 0, 10);

或者你可以使用logncdf函数,这样可能会更干净。