To calculate the uniform distribution in MATLAB, you can use the rand function. The rand function generates uniformly distributed random numbers between 0 and 1. If you want to generate uniformly distributed random numbers between a and b, you can use the following formula:
15 chars2 lines
Here, the term (b-a) determines the width of the interval, and rand generates a random number between 0 and 1. By multiplying (b-a) with rand, we obtain a random number between 0 and (b-a). Finally, by adding a to this random number, we obtain a random number between a and b.
To generate a vector of n random numbers between a and b, you can use the following code:
50 chars5 linesIn this example, we generate 1000 random numbers between 1 and 10 and store them in the vector X.
gistlibby LogSnag