Generates a vector of chi-square random variables with the given number of degrees of freedom. The general syntax for its use is
y = randchi(n)
where n
is an array containing the degrees of freedom for
each generated random variable.
A chi-square random variable is essentially distributed as the squared Euclidean norm of a vector of standard Gaussian random variables. The number of degrees of freedom is generally the number of elements in the vector. In general, the PDF of a chi-square random variable is
First, a plot of the PDF for a family of chi-square random variables
--> f = []; --> x = (1:100)/10; --> for n=1:7;t=x.^(n/2-1).*exp(-x/2);f(n,:)=10*t/sum(t);;end --> plot(x,f');
The PDF is below:
Here is an example of using randchi
and randn
to compute
some chi-square random variables with four degrees of freedom.
--> randchi(4*ones(1,6)) ans = <float> - size: [1 6] Columns 1 to 3 5.5105934 5.5192165 9.6636553 Columns 4 to 6 5.8893781 3.9296782 2.6969872 --> sum(randn(4,6).^2) ans = <double> - size: [1 6] Columns 1 to 2 0.558546486399838 1.744416336709659 Columns 3 to 4 0.0557125714633188 4.101569338293578 Columns 5 to 6 2.119902821322430 0.922725890306646