<< distfun_chi2pdf Chi-Square distfun_chi2stat >>

Distfun >> Distfun > Chi-Square > distfun_chi2rnd

distfun_chi2rnd

Chi-Square random numbers

Calling Sequence

R = distfun_chi2rnd(k)
R = distfun_chi2rnd(k,[m,n])
R = distfun_chi2rnd(k,m,n)

Parameters

k :

a n-by-m matrix of doubles, the number of degrees of freedom, k>0 (can be non integer)

m :

a 1x1 matrix of floating point integers, the number of rows of R

n :

a 1x1 matrix of floating point integers, the number of columns of R

R:

a matrix of doubles, the positive random numbers.

Description

Generates random variables from the Chi-Sqaure distribution function.

Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.

Examples

// set the initial seed for tests
distfun_seedset(1);
// Test with expanded k
computed = distfun_chi2rnd((1:6)')
expected = [
1.8608435
1.2995079
2.8402769
0.9538728
4.5217814
2.9898461
]

// Check R = distfun_chi2rnd(k,v)
computed = distfun_chi2rnd(2,[4 5])

// Check mean and variance
N = 50000;
k = 3;
computed = distfun_chi2rnd(k,[1 N]);
c = mean(computed(1:N))
d = st_deviation(computed(1:N) )
[M,V] = distfun_chi2stat (k)

// Compare histogram of random numbers
// with PDF.
k=5;
R=distfun_chi2rnd(k,10000,1);
scf();
histplot(30,R);
x=linspace(0,25,1000);
y=distfun_chi2pdf(x,k);
plot(x,y,"b-");
xtitle("Chi-square random numbers","X","Density");
legend(["Empirical","PDF"]);

Bibliography

http://en.wikipedia.org/wiki/Chi-squared_distribution

Authors


Report an issue
<< distfun_chi2pdf Chi-Square distfun_chi2stat >>