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.
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
Means of multivariate normal distributions, specified as a
1-by-d numeric vector or an
m-by-d numeric matrix.
mu is a vector, then
mvnrnd replicates the vector to match the
trailing dimension of
mu is a matrix, then each row of
mu is the mean vector of a single
multivariate normal distribution.
sigma— Covariances of multivariate normal distributions
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.
sigma is a matrix, then
mvnrnd replicates the matrix to match the
number of rows in
sigma is an array, then each page of
the covariance matrix of a single multivariate normal distribution
and, therefore, is a symmetric, positive semi-definite
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
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
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.
mvnrnd requires the matrix
be symmetric. If
sigma has only minor asymmetry, you can
(sigma + sigma')/2 instead to resolve the
In the one-dimensional case,
sigma is the variance, not
the standard deviation. For example,
mvnrnd(0,4) is the same
4 is the variance
2 is 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.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).