I'm definitely doing the exponential distribution wrong, am I?

3 ビュー (過去 30 日間)
Kevin Nelson
Kevin Nelson 2022 年 9 月 20 日
コメント済み: VBBV 2022 年 10 月 24 日
N = 1e4;
a=0; b=1;
x = a+(b-a)*rand([N,1]);
lambda = 1;
Y = -log(x)/lambda;
figure(1); clf
histogram(x,20,'Normalization','pdf');
hold on;
histogram(Y,20,'Normalization' , 'pdf')
hold off
xlabel('random variable $x$','Interpreter','latex','FontSize',20)
ylabel('Probability density','Interpreter','latex','FontSize',20)
title('Continuous uniform PDF','Interpreter','latex','FontSize',20)
  1 件のコメント
Kevin Nelson
Kevin Nelson 2022 年 9 月 20 日
I'm trying to superimpose an exponential distribution to a uniform distribution, and it's not coming out right. Why? I was told I can transform from uniform to exponential by using the equation Y = − ln X/λ. Am I doing it wrong?

サインインしてコメントする。

回答 (2 件)

VBBV
VBBV 2022 年 9 月 20 日
編集済み: VBBV 2022 年 9 月 20 日
N = 1e4;
a=0; b=1;
x = (a+(b-a)*rand([N,1]));
lambda = 11; % try with different lambda values
Y = -log(x)/lambda;
figure(1); clf
histogram(x,20,'Normalization','pdf');
hold on;
histogram(Y,20,'Normalization' , 'pdf')
hold off
xlabel('random variable $x$','Interpreter','latex','FontSize',20)
ylabel('Probability density','Interpreter','latex','FontSize',20)
title('Continuous uniform PDF','Interpreter','latex','FontSize',20)
  5 件のコメント
Kevin Nelson
Kevin Nelson 2022 年 9 月 20 日
okay thank you very much
VBBV
VBBV 2022 年 10 月 24 日
Please accept the answer if it worked for you

サインインしてコメントする。


Chunru
Chunru 2022 年 9 月 20 日
% if X is uniform on [0,1] then −loge(X) follows an exponential distribution with parameter 1
N = 1e5;
a=0; b=1;
x = a+(b-a)*rand([N,1]);
lambda = 1;
Y = -log(x)/lambda;
figure(1); clf
histogram(x,100,'Normalization','pdf');
hold on;
histogram(Y,100,'Normalization' , 'pdf')
xx = 0:0.1:10;
plot(xx, pdf('Uniform', xx, 0, 1), 'r--', 'Linewidth', 2);
plot(xx, pdf('Exponential', xx, 1), 'b--', 'Linewidth', 2);
xlim([0 10])
hold off
xlabel('random variable $x$','Interpreter','latex','FontSize',20)
ylabel('Probability density','Interpreter','latex','FontSize',20)
title('Continuous uniform PDF','Interpreter','latex','FontSize',20)
legend('Hist-unif', 'Hist-exp', 'Unif', 'Exp')
  3 件のコメント
Chunru
Chunru 2022 年 9 月 20 日
Yes. Your code is correct. I just change the number of samples and bin number to make the hist closer to the ideal pdf.
Kevin Nelson
Kevin Nelson 2022 年 9 月 20 日
Okay, thank you very much

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by