Truncated Normal random numbers
R=distfun_tnormrnd(mu,sigma,a,b) R=distfun_tnormrnd(mu,sigma,a,b,[m,n]) R=distfun_tnormrnd(mu,sigma,a,b,m,n)
a matrix of doubles, the average
a matrix of doubles, the standard deviation. sigma>0.
a matrix of doubles, the lower bound
a matrix of doubles, the upper bound (with a<=b)
a 1-by-1 matrix of floating point integers, the number of rows of R
a 1-by-1 matrix of floating point integers, the number of columns of R
a matrix of doubles, the random numbers.
Generates random variables from the Normal distribution function.
Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
// Set the seed so as to always get the same results. distfun_seedset(1); R=distfun_tnormrnd(3,5,2,4) // Test sigma expansion R=distfun_tnormrnd(3,5:7,2,4) // Test mu expansion R=distfun_tnormrnd(3:6,5,2,4) // Test with v R=distfun_tnormrnd(3,5,2,4,[3 2]) // Test with m, n R=distfun_tnormrnd(3,5,2,4,3,2) // Make a plot of the actual distribution of the numbers a=-10; b=10; N=1000; x=linspace(a,b,1000); y1=distfun_tnormpdf(x,-8,2,a,b); R1=distfun_tnormrnd(-8,2,a,b,N,1); y2=distfun_tnormpdf(x,0,2,a,b); R2=distfun_tnormrnd(0,2,a,b,N,1); y3=distfun_tnormpdf(x,9,10,a,b); R3=distfun_tnormrnd(9,10,a,b,N,1); y4=distfun_tnormpdf(x,0,10,a,b); R4=distfun_tnormrnd(0,10,a,b,N,1); scf(); subplot(2,2,1) histplot(20,R1); plot(x,y1); s="$\textrm{Trunc. normal [-10,10], }\mu=-8,\sigma=2$"; xtitle(s,"X","Frequency"); legend(["Data","PDF"]); // subplot(2,2,2) histplot(20,R2); plot(x,y2); s="$\textrm{Trunc. normal [-10,10], }\mu=0,\sigma=2$"; xtitle(s,"X","Frequency"); legend(["Data","PDF"]); // subplot(2,2,3) histplot(20,R3); plot(x,y3); s="$\textrm{Trunc. normal [-10,10], }\mu=9,\sigma=10$"; xtitle(s,"X","Frequency"); legend(["Data","PDF"]); // subplot(2,2,4) histplot(20,R4); plot(x,y4); s="$\textrm{Trunc. normal [-10,10], }\mu=0,\sigma=10$"; xtitle(s,"X","Frequency"); legend(["Data","PDF"]); | ![]() | ![]() |
http://en.wikipedia.org/wiki/Truncated_normal_distribution