Home > Computer Tutorials > Computer Knowledge > Use matlab to generate a random decimal between 0 and 1

Use matlab to generate a random decimal between 0 and 1

WBOY
Release: 2024-01-23 15:36:06
forward
1114 people have browsed it

How to use matlab to generate random decimals between 0 and 1

MATLAB function rand

Generates uniform random numbers in the interval (0, 1), which are evenly distributed in

Between (0,1), we can use a value called seed to control the number of times random numbers are generated. The uniform random number function has two syntax forms: rand(n) and rand(m,n). Among them, rand(n) will generate a matrix containing n*n random numbers, and rand(m,n) will generate a matrix containing m*n random numbers. It should be noted that the random values ​​generated each time are different. These values ​​represent random and unpredictable results, which is also the purpose of using random numbers. We can use these random numbers to represent the irregular amplitude of a certain signal or the probability of an event occurring. Uniform random numbers have the property of evenly distributing values ​​over an interval, which can be seen from its probability density function.

The PDF distribution is similar to the distribution of a bar chart, indicating that each random value has the same probability of occurrence, so it is called a uniform random number (function, PDF).

Try it help rand

How to generate N random numbers and a fixed value M in matlab

Implementation method: First use the rand() function to generate N random numbers. Assume that the sum of N random numbers is S at this time, then change each random number to M/S times the original, thus achieving N The sum of random numbers is the effect of a fixed value M.

A = rand(1,N); S = sum(A); B = A*M/S;

The following is an example demonstration and detailed explanation: generate 9 random numbers whose sum is a fixed value of 10.

1. Open the matlab software and enter in the command window: A = rand(1,9), which means to generate 9 random numbers between 0 and 1. The output is as follows:

Use matlab to generate a random decimal between 0 and 1

2. Continue to input: S = sum(A); B = A*10/S, which means changing each random number to 10/sum(A) times the original value. At this time, the array B is . The output results are as follows:

Use matlab to generate a random decimal between 0 and 1

3. In order to verify whether the sum of the obtained array B is a fixed value of 10, enter: sum(B) in the command window. The result is as follows:

Use matlab to generate a random decimal between 0 and 1

How to use matlab to generate a random number function

rand(n): Generate an n-order random number square matrix between 0 and 1 rand(m,n): Generate an m*n random number matrix between 0 and 1 (ready-made function)

in addition:

Matlab random number generation function

betarnd Beta distributed random number generator

binornd Binomial distribution random number generator

chi2rnd Chi-square distribution random number generator

exprnd Exponentially distributed random number generator

frnd f-distributed random number generator

gamrnd Gamma distributed random number generator

geornd Geometrically distributed random number generator

hygernd Hypergeometric distribution random number generator

lognrnd Random number generator for lognormal distribution

nbinrnd Negative binomial distribution random number generator

ncfrnd Random number generator for non-central f distribution

nctrnd non-central t-distributed random number generator

ncx2rnd Non-central chi-square distribution random number generator

normrnd Normal (Gaussian) distributed random number generator

poissrnd Poisson distributed random number generator

raylrnd Rayleigh distributed random number generator

trnd Random number generator for Student's t distribution

unidrnd Discrete uniformly distributed random number generator

unifrnd Continuous uniformly distributed random number generator

weibrnd Weibull distribution random number generator

The above is the detailed content of Use matlab to generate a random decimal between 0 and 1. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template