<分区>
我想使用指数分布在特定区间内生成一个随机数。我的问题是,如果我使用 exprnd 我无法控制间隔,我只能给出一个平均值,但这不符合我的需要。 是否有其他功能或我必须使用的一些技巧?
<分区>
我想使用指数分布在特定区间内生成一个随机数。我的问题是,如果我使用 exprnd 我无法控制间隔,我只能给出一个平均值,但这不符合我的需要。 是否有其他功能或我必须使用的一些技巧?
最佳答案
这有帮助吗? (或者我误解了这个问题?)
%#Set the parameters
T = 2000; %#Number of observations to simulate
Mu = 0.5; %#Exponential distribution parameter
LB = 0; %#Lower bound on exponential distribution
UB = 1; %#Upper bound on exponential distribution
%#Validate the parameters
if LB < 0 || UB < 0; error('Bounds must be non-negative'); end
if Mu <= 0; error('Mu must be positive'); end
%#Determine LB and UB in terms of cumulative probabilities
LBProb = expcdf(LB, Mu);
UBProb = expcdf(UB, Mu);
%#Simulate uniform draws from the interval LBProb to UBProb
Draw = LBProb + (UBProb - LBProb) .* rand(T, 1);
%#Convert the uniform draws to exponential draws using the inverse cdf
X = expinv(Draw, Mu);
关于matlab - 一定区间内服从指数分布的随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13218100/