Normalizing a Gaussian Distribution

Assuming a Gaussian distribution with mean of zero and standard deviation of one, I would like to normalize this for an arbitrary mean and standard deviation.

I know you're supposed to add the mean and multiply by the standard deviation. It's the multiplying by the standard deviation that I'm not seeing.

I have a set of $2^{20}$ Gaussian-distributed random numbers generated with MatLab's randn() function. Let's call it matrix $A$. Suppose I have another matrix $B = 40 + 10A$. When I plot $A$ and $B$ in a histogram together, $B$ and $A$ have different widths as they should, but the same height, as shown in the images below.

Normally (no pun intended) I would expect to see something like this, with different heights:

But instead, I'm seeing something like this:

• The problem is that the widths of the histogram bins are different. – Rahul Aug 15 '13 at 20:03
• ah, much better – audiFanatic Aug 15 '13 at 20:22

Histogram will show you the number of samples in each bucket. Since your sample size and number of buckets didn't change the values in histogram will stay the same. You can scale the number of bins to get closer to the graph you're expecting.

Note that it will still be discrete bars. To get a smooth curve you can use kernel density smoothing technique.

• Thanks, that's much better! – audiFanatic Aug 15 '13 at 20:22

The Histogram doesn't how densities but partial cumulative distributions over intervals [A, B). Mathematica has an option to translate into densities and normalize different graphs.

If you want to see a probability density-like curve, you can use a kernel-density approach rather than a histogram. In Matlab, using ksdensity:

mu = [0;0;0;-2];
sig2 = [0.2;1;5;0.5];
x = -5:0.1:5;
y = zeros(length(mu),length(x));
for i = 1:length(mu)
r = mu(i)+sqrt(sig2(i))*randn(1,1e6);
y(i,:)= ksdensity(r,x);
end
figure;
plot(x,y)
axis([min(x) max(x) 0 1])
grid on
xlabel('x');
ylabel('F(x)')


which produces a figure like this

Like with histograms, there are many caveats, so read the help and documentation. Of course if you actually want the probability density function of a normal distribution, histogram-ing or performing kernel-density smoothing is not the way to go about it.