<?xml version="1.0" encoding="UTF-8"?>

<!--
 *
 * This help file was generated from distfun_binornd.sci using help_from_sci().
 *
 -->

<refentry version="5.0-subset Scilab" xml:id="distfun_binornd" xml:lang="en"
          xmlns="http://docbook.org/ns/docbook"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg"
          xmlns:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:scilab="http://www.scilab.org"
          xmlns:db="http://docbook.org/ns/docbook">

  <refnamediv>
    <refname>distfun_binornd</refname>
    <refpurpose>Binomial random numbers</refpurpose>
  </refnamediv>


<refsynopsisdiv>
   <title>Calling Sequence</title>
   <synopsis>
   x = distfun_binornd(N,pr)
   x = distfun_binornd(N,pr,[m,n])
   x = distfun_binornd(N,pr,m,n)
   
   </synopsis>
</refsynopsisdiv>

<refsection>
   <title>Parameters</title>
   <variablelist>
   <varlistentry><term>N :</term>
      <listitem><para> a matrix of doubles , the total number of binomial trials . N belongs to the set {1,2,3,4,.......}</para></listitem></varlistentry>
   <varlistentry><term>pr :</term>
      <listitem><para> a matrix of doubles, the probability of getting success in a Bernoulli trial. pr in [0,1].</para></listitem></varlistentry>
   <varlistentry><term>m :</term>
      <listitem><para> a 1-by-1 matrix of floating point integers, the number of rows of x</para></listitem></varlistentry>
   <varlistentry><term>n :</term>
      <listitem><para> a 1-by-1 matrix of floating point integers, the number of columns of x</para></listitem></varlistentry>
   <varlistentry><term>x:</term>
      <listitem><para> a matrix of doubles, the random numbers, in the set {0,1,2,3,...}.</para></listitem></varlistentry>
   </variablelist>
</refsection>

<refsection>
   <title>Description</title>
   <para>
Generates random variables from the Binomial distribution function.
   </para>
   <para>
Any scalar input argument is expanded to a matrix of doubles
of the same size as the other input arguments.
   </para>
   <para>
If N&lt;=2147483647, the algorithm is based on
   </para>
   <para>
Kachitvichyanukul, V. and Schmeiser, B. W. "Binomial Random Variate Generation.",
Communications of the ACM, 31, 2 (February, 1988) 216.
   </para>
   <para>
If N is larger, then we invert the CDF.
   </para>
   <para>
</para>
</refsection>

<refsection>
   <title>Examples</title>
   <programlisting role="example"><![CDATA[
// Check with expanded N
N = [10 100 1000 10000]
pr = 0.1
x = distfun_binornd(N, pr)

// Check with expanded pr
N =100
pr = [0.1 0.2 0.3 0.4]
x = distfun_binornd(N, pr)

// Check x = distfun_binornd(pr,v)
x = distfun_binornd(100,0.2,[4 5])

//Check mean and variance
N = 1000
pr = 0.3
n = 5000
x = distfun_binornd(N,pr,[1 n]);
Mx = mean(x)
Vx = variance(x)
[M,V] = distfun_binostat(N,pr)

// Check actual distribution
N=10;
pr=0.7;
K=10000;
h=scf();
x=distfun_binornd(N,pr,1,K);
distfun_inthisto(x);
h.children.children(1).children.background=-2;
x=0:N;
y=distfun_binopdf(x,N,pr);
plot(x,y,"ro-");
xtitle("Binomial Random Numbers","X","Density")
legend(["Empirical","Density"]);

   ]]></programlisting>
</refsection>

<refsection>
   <title>Bibliography</title>
   <para>http://en.wikipedia.org/wiki/Binomial_distribution</para>
</refsection>

<refsection>
   <title>Authors</title>
   <simplelist type="vert">
   <member>Copyright (C) 2012 - Prateek Papriwal</member>
   <member>Copyright (C) 2012 - 2014 - Michael Baudin</member>
   </simplelist>
</refsection>
</refentry>
