Why are my Gaussian distributions not properly being generated?

조회 수: 3 (최근 30일)
Kevin Nelson
Kevin Nelson 2022년 9월 13일
답변: Walter Roberson 2022년 9월 13일
N1 = 1e4;
Y1 = randn(N1,-5,4);
%
N2 = 1e4;
Y2 = randn(N2,5,3);
N3 = 1e4;
Y3 = randn(N3,0,5);
figure(5); clf
histogram(Y3,'Normalization','pdf');
hold on;
%plot(0:Y3-1,1/Y3*ones(size(1:Y3)),'r','LineWidth',2), could not get this
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월 13일
I'm supposed to be adding Y1 and Y2 (I was told to add the means (-5 + 5 = 0) and the SD (sqrt(4^2 + 3^2) to get Y3, if that is even right

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2022년 9월 13일
Y1 = randn(N1,-5,4);
The numeric parameters to randn() are all sizes so you asked for an array that is N1 by negative 5 by 4.
I suspect that you want
Y1 = randn(1,N1) * 4 - 5
which is multiply by standard deviation and add the mean.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by