Need HELP w/ Matlab problem.

supesman

Senior member
Feb 11, 2001
714
0
0
I have a matlab question, i hope someone is familiar with this as I am not. Here's the problem:

Generate a stream of i.i.d (independent identically distributed random variables U={U(N), N>=n>=1} which are uniformly distributed over [0,1], for N=1000, 5000, 10000.

Use resulting streams to draw probability distribution histograms which show the probabilities that U is in the interval (0.1i,0.1i+0.1], for i=0,1...,9. Compute the sample means and variances, for each of the three runs.

I'd appreciate it if someone could help me get started, i don't even know how to generate the i.i.d. Thanks in advance.
 
Feb 7, 2000
1,004
0
0
use a while loop
N is the number of runs in the loop
there's a random number generator function in matlab that i think gives a random number from 0-1
every number that is generated, add it to a matrix

once you get the numbers in the matrix the resulting calculations are easy
im assuming that you can add the numbers in the matrix and find the mean and all that, its not hard

if you need more help then click on my profile and email me

[edit] actually ill give ya some code. i dont know the histogram function but youll need to get a matrix for that too. then use another while loop to browse through all the values in the random number matrix, meanwhile create another matirx with values that represent the height of the histogram bars

ill start you off for the code to distribute the random number matrix

the code isnt perfect and i forget the syntax but here it is

N=1;
U=zeros[N];
while N<1001;
U(N)=random(1);
N=N+1;
end while;

that will give you a matrix that is 1xN in dimension and each value is a random number from 0 to 1

to get the height of the bars in the histogram you would do this

N=1;
Y=zeros[4];
while N<1001;
if U(N)<.25 then;
Y[1]=Y[1]+1;
end if;
if U(N)<.5 and U(N)>.25 then;
Y[2]=Y[2]+1;
end if;
if U(N)<.75 and U(N)>.5 then;
Y[3]=Y[3]+1;
end if;
if U(N)<1 and U(N)>.75 then;
Y[4]=Y[4]+1;
end if;
N=N+1;
end while;

that would make the histogram into 4 ranges
again, my syntax is off but there ya go
and to actually produce the histogram matrix Y would be one of the arguments[/edit]
 

supesman

Senior member
Feb 11, 2001
714
0
0
Wow, thanks so much josphstalinator, i really needed to get myself started with this thing. I actually used the hist function to graph it but I'm sure your method would've worked as well. Thanks again, really appreciate it.