# Homework Help: MATLAB Question?

1. Oct 10, 2008

### coffeem

1. The problem statement, all variables and given/known data

Plot a suitably scaled normal distribution on top of a histogram made with 100 random values.

3. The attempt at a solution

x = -2,9:0.1:2.9;

y = randn(100,1);

nd = exp(-x.^2/2)/sqrt(2*pi);

hist(y,x);

hold on;

plot(x,nd);

plot(-x,nd);

holf off;

This is not working. What am I doing wrong? Also how do I ensure that it is suitably scaled?

Thanks

2. Oct 10, 2008

### eys_physics

Hey
I think you have to change "plot(y,x)" to "plot(x,y)". Remove also "hold off;" (written as "holf off" but I suppose it is an type error). I don't understand why you first plot nd as a function of x and then as a function of -x. As nd is an even function you only need to plot it as a function of x.

3. Oct 10, 2008

### coffeem

Umm i'll try and explain my thoughts then.

I plotted fn as both a function and a function of -x so that I got your average bell shaped curve. for this I need to go back to -3 as well as +3 on the x-axis. When I tried changing it to just x it did not work sadly.

Also I need to plat a histogram so changing it to plot would not work. the only way I can get the historgram to work is by plotting (y,x). thanks

4. Oct 10, 2008

### coffeem

I have not got this far:

%%
x = 0:0.1:3;

nd = 10.*exp(-x.^2/2)/sqrt(2*pi);

plot(x,nd);

hold on;

plot(-x,nd);
%%
x = -2.9:0.1:2.9;

y = randn(100,1);

hist (y,x);

hold off

This will give me what I want. So all I need to do is suitably scale it. How do I do this? Is there some way I can tell how well it matches?

Thanks