我在绘制三角形分布的 CDF 时遇到了一些错误;我可以使用在 MATLAB 中生成三角形分布来绘制直方图,但是如何绘制 CDF?
n = 10000; %Random number
a = 0.26; %Min
b = 0.46; %Max
c = 0.35; %Mode
u = rand(n, 1);
x = zeros(n, 1);
for i = 1:n
U = u(i);
if U < (c-a)/(b-a);
X = a + sqrt(U*(b-a)*(c-a));
else
X = b - sqrt((1-U)*(b-a)*(b-c));
end
x(i) = X;
end
hist(x,100)
if a <= x && a <=c
cdf = (x-a)^2/12
elseif c <= x && x <= b
cdf = 1-(b-x)^2/4
end
if 0 <= p && p <= 0.75
INV = a+2*sqrt(3*p);
elseif 0.75 <= p && p <= 1
INV = b-2*sqrt(1-p)
end