Matlab is a commonly used software for us. Friends who do random processes or probability often use some random numbers. But how are these data generated? The following introduces some common random numbers in matlab.
Methods that matlab can use to generate random numbers:
1. Uniform distribution:
■ unifrnd (a, b, m, n)
Generate m*n order [a, b] uniform distribution
■ unifrnd (a,b )
Generate a uniform random number [a,b]
Recommended study "Introduction to Programming"
Example:
2. rand (m, n);
produces m*n order [0, 1] uniformly Distributed random number matrix
■ rand(n);
Generate n*n order [0,1] uniformly distributed random numbers
Example:
##3、binornd(n,p,[M,N,P,...])
The generated numbers are random numbers that obey the binomial distribution. The parameters of the binomial distribution are: n and p.Consider a target shooting example. Each shot The hit rate is p, and a total of N guns are fired, then the total number of hits obeys the binomial distribution with parameters (N, p). Note that p must be less than or equal to 1 and non-negative, and N must be an integer. ■ binornd(n,p,[M,N,P,...])
The generated random numbers obey the binomial distribution with parameters (N, p) , these random numbers are arranged into an M*N*P... order matrix. If only M is written, an M*M matrix will be generated;Example:
4, unidrnd(N, m,n)
Generate an m*n order discrete uniformly distributed random number matrix; generate an mm*nn matrix with a value between 1-NExample:
5, exprnd (mu ,m, n)
Produces m*n order expected value A random number matrix of exponential distribution for muExample: There are also some other random numbers, which will not be introduced here. The methods are other This is similar to For more related programming tutorials, please pay attention to
PHP Chinese website!
The above is the detailed content of How to generate random numbers in matlab. For more information, please follow other related articles on the PHP Chinese website!