matlab如何产生二维正态分布随机数
matlab如何产生二维正态分布随机数
matlab上有现成的函数,函数名称为:mvnrnd(mu,sigma,cases,t)帮助文件如下
MVNRND Random vectors from the multivariate normal distribution.
% R = MVNRND(MU,SIGMA) returns an n-by-d matrix R of random vectors
% chosen from the multivariate normal distribution with mean vector MU,
% and covariance matrix SIGMA.MU is an n-by-d matrix,and MVNRND
% generates each row of R using the corresponding row of MU.SIGMA is a
% d-by-d symmetric positive semi-definite matrix,or a d-by-d-by-n array.
% If SIGMA is an array,MVNRND generates each row of R using the
% corresponding page of SIGMA,i.e.,MVNRND computes R(I,:) using MU(I,:)
% and SIGMA(:,:,I).If MU is a 1-by-d vector,MVNRND replicates it to
% match the trailing dimension of SIGMA.
%
% R = MVNRND(MU,SIGMA,CASES) returns a CASES-by-d matrix R of random
% vectors chosen from the multivariate normal distribution with a common
% 1-by-d mean vector MU,and a common d-by-d covariance matrix SIGMA.
% R = MVNRND(MU,SIGMA,CASES,T) supplies the Cholesky factor T of
% SIGMA,so that SIGMA == T'*T.No error checking is done on T.
%
% [R,T] = MVNRND(...) returns the Cholesky factor T,so it can be
% re-used to make later calls more efficient.
%
% If SIGMA is a 3-dimensional array,MVNRND ignores the input T and does
% not create the output T.
% Copyright 1993-2002 The MathWorks,Inc.
% $Revision:2.13 $ $Date:2002/03/28 16:51:29 $
同时可以自己编写代码,先产生一维标准正态分布随机数,
u1和u2是独立同分布的(0,1)的均值分布随机数
令:x1=(-2lnu1)^0.5×cos(2*pi*u2)
x2=(-2lnu1)^0.5×sin(2*pi*u2)
pi为园周率!
x1和x2独立,服从标准正态分布.