Why are my Gaussian distributions not properly being generated?

1 view (last 30 days)
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 Comment
Kevin Nelson
Kevin Nelson on 13 Sep 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

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 13 Sep 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.

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!