I. Theoretical preparation
Matlab function randn: a random number or matrix function that generates a normal distribution with the mean value 0, variance σ ^ 2 = 1, and standard deviation σ = 1.
Usage: Y = randn (n) returns a matrix of N * n random items. If n is not the number, an error is returned.
Y = randn (m, n) or Y = randn ([m n]) returns a random matrix of M * n.
Y = randn (M, N, P ,...) or y = randn ([m n p...]), generate a random array (it seems like a 3D array. See the following example ).
1: >> rand(1,2,3)
2: ans(:,:,1) =
3: 0.445586200710899 0.646313010111265
4: ans(:,:,2) =
5: 0.709364830858073 0.754686681982361
6: ans(:,:,3) =
7: 0.276025076998578 0.679702676853675
Y = randn (SIZE (A), returns a random array with the same dimension as.
Randn
S = randn ('state'). It is estimated that random seeds are initialized in C ++.
Ii. Example Analysis
Generate a matrix of the specified Mean and variance for a random distribution: multiply the result generated by randn by the standard deviation, and then add the expected mean. For example, a random number of 5*5 with an average value of 0.6 and a variance of 0.1 is generated as follows:
1: x = .6 + sqrt(0.1) * randn(5)
Other similar functions: Rand, randperm, sprand, sprandn
Iii. Expansion
Use MATLAB to randomly generate 60 positive numbers 1 + fix (365 * rand (365) between 1 and. Fix is the entire function.
Use the rand function to randomly retrieve 100 numbers from-1 to 2 x1, x2,..., x = rand (1,100) * 2-1.
Rand () function usage in MATLAB