Code covered by the BSD License  

Highlights from
Multivariate normal random vectors with fixed mean and covariance matrix

Be the first to rate this file! 8 Downloads (last 30 days) File Size: 3.11 KB File ID: #34974
image thumbnail

Multivariate normal random vectors with fixed mean and covariance matrix

by

Mike Sheppard

 

07 Feb 2012 (Updated )

Random vectors from the multivariate normal distribution with fixed mean and covariance matrix.

| Watch this File

File Information
Description

 MVNRND2 Random vectors from the multivariate normal distribution.
 R = MVNRND2(MU,SIGMA,NUM) returns a NUM-by-D matrix R of multivariate normal random vectors whose mean and covariance matrix match the given input parameters, MU (1-D vector) and SIGMA (D-by-D matrix)
 
 [...] = MVNRND2(...,COVNORM) determines normalization for covariance
 0 : Normalizes by NUM-1. This makes cov(R) the best unbiased estimate of the covariance matrix (Default)
 1 : Normalizes by NUM and produces the second moment matrix of the observations about their mean.
 
 MU : Either a 1-by-D row vector, or a scalar across dimensions.
 SIGMA : Either a D-by-D positive semi-definite matrix, or 1-by-D row vector of a diagonal matrix, or scalar representing that value along the diagonal.
 NUM : Positive integer at least D+1 in value.
 COVNORM : 0 or 1 (Any non-zero value will be taken as 1)
 
 Note: This is different from the MVNRND function in the Statistics Toolbox, as that samples from a multivariate normal distribution with mean MU and covariance SIGMA. The sampled mean and covariance may be different from the given inputs. This functions finds a collection of multivariate normal random vectors whose mean and covariance match the given input parameters, MU and SIGMA.
 
 Example 1:

 Find 5 numbers from the univariate normal distribution that have mean 50 and sample variance of 2. Show output and test output to determine if answer is valid.
 r=mvnrnd2(50,2,5), mean(r), cov(r)

 
 Example 2:

 Find 1000 bivariate normal random vectors with mean [1 2] and second-moment matrix of [2 .3; .3 2]. Test output to determine if answer is valid.
 r=mvnrnd2([1 2],[2 .3; .3 2],1000,1); mean(r), cov(r,1)

 
 Example 3:
 Find 1e6 multivariate normal random vectors of dimension 5 with mean [5 -4 3 -2 1], with variances [1 2 3 4 5] and that are uncorrelated. Test output to determine if answer is valid.

 r=mvnrnd2([5 -4 3 -2 1],[1 2 3 4 5],1e6); mean(r), cov(r)

 
 Example 4:
 (This example requires the Statistics Toolbox)
 MVNRND in the Statistics Toolbox samples from a multivariate distribution with the given input parameters. MVNRND2 finds a collection of multivariate normal random vectors whose mean and covariance match the given input parameters, MU and SIGMA. Show both results for the same input.

 r=mvnrnd([0 -3],[2 .3; .3 1],10); mean(r), cov(r)
 r2=mvnrnd2([0 -3],[2 .3; .3 1],10); mean(r2), cov(r2)

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Updates
09 Feb 2012

Reworded help and title, fixed small bug.

04 Apr 2012

Updated help section

Contact us