?? gngauss.m
字號:
function[gsrv1,gsrv2]=gngauss(m,sgma)
% 高斯隨機變量1,高斯隨機變量2,發(fā)生器generate
% I was asked to realize the gaussian distribution,which may be generated by the matlab function randn,normrnd......
% but it is still necessary to know how to realize it just by uniform random numbers in (0,1).
% here is a way.for simplicity I suppose sigma=1 and u=0,the standard normal distribution.
% we should know that we can not give the analystic equation of the probabilty distrbution function of gaussian distribution.
% but we know that R(x)=1-exp(-x^2/(2*sigma^2)) when x>=0 and R(x)=0 when x<0.R(x) is the probability distribution function of relay distribution.
% and the gaussian distribution has the following relationship:
% c=x*cos(theta)
% d=x*sin(theta)
% where c,d are two gaussian variables,x is the variable in the former function.
% theta is the random variable in the uniform distribution of(0,2*pi).
% if we have R(x)=A,A is uniformly distributed in (0,1)
% then x= sqrt(2*sigma^2*ln(1/1-A)).
% and another variable B uniformly distributed in (0,1),suppose
% theta=2*pi*B
% then we have two statically independent gaussian random variables c ,d .
% if you want to have more variables,just to make A ,B vectors.
% the realization:
% m=0; sgma=1;
% N=1000;
% u=rand(1,N);
% % z=sgma*(sqrt(2*log(1./(1-u))));
% u=rand(1,N);
% gsrv2=m+z.*sin(2*pi*u);
% gsrv1=m+z.*cos(2*pi*u);
% g=[gsrv1,gsrv2];
% hist(g);
% if the gaussian distribution is not standard, just to change m and sigma.
if nargin==0,
m=0;sgma=1;
elseif nargin==1,
sgma=m;m=0;
end;
u=rand;
z=sgma*(sqrt(2*log(1/(1-u))));
u=rand;
gsrv1=m+z*cos(2*pi*u);
gsrv2=m+z*sin(2*pi*u);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -