Why are my Gaussian distributions not properly being generated?

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Kevin Nelson
Kevin Nelson il 13 Set 2022
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

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 13 Set 2022
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