Multivariate normal random numbers
returns a matrix
R = mvnrnd(
n random vectors
chosen from the same multivariate normal distribution, with mean vector
mu and covariance matrix
more information, see Multivariate Normal Distribution.
Generate Multivariate Normal Random Numbers
Generate random numbers from the same multivariate normal distribution.
Sigma, and generate 100 random numbers.
mu = [2 3]; Sigma = [1 1.5; 1.5 3]; rng('default') % For reproducibility R = mvnrnd(mu,Sigma,100);
Plot the random numbers.
Sample from Different Multivariate Normal Distributions
Randomly sample from five different three-dimensional normal distributions.
Specify the means
mu and the covariances
Sigma of the distributions. Let all the distributions share the same covariance matrix, but vary the mean vectors.
firstDim = (1:5)'; mu = repmat(firstDim,1,3)
mu = 5×3 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5
Sigma = eye(3)
Sigma = 3×3 1 0 0 0 1 0 0 0 1
Randomly sample once from each of the five distributions.
rng('default') % For reproducibility R = mvnrnd(mu,Sigma)
R = 5×3 1.5377 -0.3077 -0.3499 3.8339 1.5664 5.0349 0.7412 3.3426 3.7254 4.8622 7.5784 3.9369 5.3188 7.7694 5.7147
Plot the results.
mu — Means of multivariate normal distributions
numeric vector | numeric matrix
Means of multivariate normal distributions, specified as a
1-by-d numeric vector or an
m-by-d numeric matrix.
muis a vector, then
mvnrndreplicates the vector to match the trailing dimension of
muis a matrix, then each row of
muis the mean vector of a single multivariate normal distribution.
Sigma — Covariances of multivariate normal distributions
symmetric, positive semi-definite matrix | numeric array
Covariances of multivariate normal distributions, specified as a d-by-d symmetric, positive semi-definite matrix or a d-by-d-by-m numeric array.
Sigmais a matrix, then
mvnrndreplicates the matrix to match the number of rows in
Sigmais an array, then each page of
Sigma(:,:,i), is the covariance matrix of a single multivariate normal distribution and, therefore, is a symmetric, positive semi-definite matrix.
If the covariance matrices are diagonal, containing variances along the
diagonal and zero covariances off it, then you can also specify
Sigma as a
1-by-d vector or a
array containing just the diagonal entries.
n — Number of multivariate random numbers
positive scalar integer
Number of multivariate random numbers, specified as a positive scalar
n specifies the number of rows in
R — Multivariate normal random numbers
Multivariate normal random numbers, returned as one of the following:
mu is a matrix and
Sigma is an array, then
Multivariate Normal Distribution
The multivariate normal distribution is a generalization of the univariate normal distribution to two or more variables. It has two parameters, a mean vector μ and a covariance matrix Σ, that are analogous to the mean and variance parameters of a univariate normal distribution. The diagonal elements of Σ contain the variances for each variable, and the off-diagonal elements of Σ contain the covariances between variables.
The probability density function (pdf) of the d-dimensional multivariate normal distribution is
where x and μ are
1-by-d vectors and Σ is a
d-by-d symmetric, positive definite matrix. Only
mvnrnd allows positive semi-definite Σ matrices,
which can be singular. The pdf cannot have the same form when Σ is
The multivariate normal cumulative distribution function (cdf) evaluated at x is the probability that a random vector v, distributed as multivariate normal, lies within the semi-infinite rectangle with upper limits defined by x:
Although the multivariate normal cdf does not have a closed form,
mvncdf can compute cdf values numerically.
mvnrndrequires the matrix
Sigmato be symmetric. If
Sigmahas only minor asymmetry, you can use
(Sigma + Sigma')/2instead to resolve the asymmetry.
In the one-dimensional case,
Sigmais the variance, not the standard deviation. For example,
mvnrnd(0,4)is the same as
4is the variance and
2is the standard deviation.
 Kotz, S., N. Balakrishnan, and N. L. Johnson. Continuous Multivariate Distributions: Volume 1: Models and Applications. 2nd ed. New York: John Wiley & Sons, Inc., 2000.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Introduced before R2006a