MATLAB code to Generate Uniform Random Variable

Therefore, the histograms should have a rectangular shape with a height of 1. In summary, the task is to generate 100,000 sets of three uniform random variables on [0,1], find the max and min of each set, derive the densities of Y and Z from theory, and compare the histograms of Y and Z to the theoretical densities.
  • #1
neeraj.patel1
4
0

Homework Statement



Generate 1,00,000 triplets(sets of three) of Uniform random variables on [0,1]. Y be max of each triple and Z be min of each triple. Derive the densities for these RV from theory and compare histograms of Y and Z with densities found in theory.

Homework Equations



rand()
hist()

The Attempt at a Solution



for i=1:100000
for j=1:3
{
a[j]=rand(1)
}
r=max(a[j],a[j+1])
mx=(r,a[j+2])
...
min...
 
Physics news on Phys.org
  • #2
...endY=mxZ=mnhist(Y,50)hist(Z,50)The densities of Y and Z can be derived theoretically by taking the cumulative distribution functions of the Uniform random variables on [0,1] and then differentiating them to obtain the density. The densities of Y and Z will both be equal to 1. The histograms of Y and Z should show uniform distribution with the same densities obtained from theory.
 

1. What is MATLAB code used for?

MATLAB is a programming language commonly used in scientific and engineering fields for data analysis, visualization, and mathematical computations.

2. How can I generate a uniform random variable in MATLAB?

To generate a uniform random variable in MATLAB, you can use the function rand or randi. For example, rand(1,10) will generate 10 random numbers between 0 and 1, while randi([a,b],1,10) will generate 10 random integers between a and b.

3. What is a uniform random variable?

A uniform random variable is a type of probability distribution where all outcomes have an equal chance of occurring. This means that the probability of any specific value appearing is the same as any other value in the range.

4. Can I specify the range of values for a uniform random variable in MATLAB?

Yes, you can specify the range of values for a uniform random variable in MATLAB by using the randi function. For example, randi([5,10],1,100) will generate 100 random integers between 5 and 10.

5. How can I plot a histogram of a uniform random variable in MATLAB?

To plot a histogram of a uniform random variable in MATLAB, you can use the histogram function. For example, if you have a vector of random numbers called x, you can plot a histogram using histogram(x). This will display a graphical representation of the frequency of each value in the vector.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
121
  • Engineering and Comp Sci Homework Help
Replies
7
Views
15K
Back
Top