## RANDCHI Generate Chi-Square Random Variable

Section: Random Number Generation

### Usage

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.

### Function Internals

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

### Example

First, a plot of the PDF for a family of chi-square random variables

    --> f = zeros(7,100);
    --> 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 6
     8.9674740  4.0014882  3.2577724  5.5460982  2.5089586  5.7587013
    --> sum(randn(4,6).^2)
    ans =
      <double>  - size: [1 6]

    Columns 1 to 3
      1.1941082197087336  10.6440952477298900   3.6228213108130904

    Columns 4 to 6
      8.4424902803814206   2.5030574101217455   1.9057629655510822