www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/GenerateGaussianDistributedRandomNumbersExample.m
%% Generate Gaussian Distributed Random Numbers % Generate Gaussian distributed random numbers using uniformly distributed % random numbers. To convert a uniformly distributed random number $x$ to a % Gaussian distributed random number $y$, use the transform % % $$y = \sqrt{2} \rm{erf^{-1}}(x).$$ % % Note that because |x| has the form |-1 + 2*rand(1,10000)|, you % can improve accuracy by using |erfcinv| instead of |erfinv|. For details, % see <docid:matlab_ref.buqdi4e-5>. % % Generate 10,000 uniformly distributed random numbers on the interval |[-1,1]|. Transform them into % Gaussian distributed random numbers. Show that the % numbers follow the form of the Gaussian distribution using a histogram plot. % Copyright 2015 The MathWorks, Inc. rng('default') x = -1 + 2*rand(1,10000); y = sqrt(2)*erfinv(x); h = histogram(y);