المتغيرات العشوائية ذات الحدين

المتغيرات العشوائية ذات الحدين

في هذا المقال سنناقش المتغيرات العشوائية ذات الحدين.
المتطلب السابق : المتغيرات العشوائية 
نوع محدد من منفصلة متغير عشوائي يحسب عدد مرات حدوث حدث معين في عدد محدد من المحاولات أو التجارب. 
لكي يكون المتغير متغيراً عشوائياً ذا الحدين يجب استيفاء جميع الشروط التالية: 
 

  1. هناك عدد محدد من التجارب (حجم عينة ثابت).
  2. وفي كل تجربة، إما أن يحدث الحدث المعني أو لا يحدث.
  3. احتمال الحدوث (أو لا) هو نفسه في كل تجربة.
  4. المحاكمات مستقلة عن بعضها البعض.


الرموز الرياضية 
 

 n = number of trials   
p = probability of success in each trial
k = number of success in n trials


الآن نحاول معرفة احتمالية نجاح k في التجارب n.
هنا احتمال النجاح في كل تجربة هو p مستقل عن التجارب الأخرى. 
لذلك نختار أولاً تجارب k التي سيكون فيها النجاح، وفي تجارب الراحة n-k سيكون هناك فشل. عدد الطرق للقيام بذلك هو 
 

المتغيرات العشوائية ذات الحدين


نظرًا لأن جميع الأحداث n مستقلة، فإن احتمال نجاح k في التجارب n يعادل مضاعفة الاحتمالية لكل تجربة.
هنا نجاح k وفشل n-k لذا فإن احتمالية كل طريقة لتحقيق نجاح k وفشل n-k هي 
 

المتغيرات العشوائية ذات الحدين


وبالتالي فإن الاحتمال النهائي هو 
 

 (number of ways to achieve k success   
and n-k failures)
*
(probability for each way to achieve k
success and n-k failure)


ثم يتم إعطاء الاحتمال المتغير العشوائي ذو الحدين بواسطة: 
 

المتغيرات العشوائية ذات الحدين


دع X يكون متغيرًا عشوائيًا ذا الحدين مع عدد التجارب n واحتمال النجاح في كل تجربة يكون p. 
يتم إعطاء العدد المتوقع من النجاح بواسطة 
 

 E[X] = np  


يتم إعطاء التباين في عدد النجاح بواسطة 
 

 Var[X] = np(1-p)  


مثال 1 : خذ بعين الاعتبار تجربة عشوائية يتم فيها إلقاء عملة معدنية متحيزة (احتمالية الصورة = 1/3) لمدة 10 مرات. أوجد احتمال أن يكون عدد الرؤوس الظاهرة 5.
حل : 
 

 Let X be binomial random variable    
with n = 10 and p = 1/3
P(X=5) = ? المتغيرات العشوائية ذات الحدين
     المتغيرات العشوائية ذات الحدين 
    

هنا هو التنفيذ لنفسه 
 

C++
   // C++ program to compute Binomial Probability   #include          #include         using     namespace     std  ;   // function to calculate nCr i.e. number of    // ways to choose r out of n objects   int     nCr  (  int     n       int     r  )   {      // Since nCr is same as nC(n-r)      // To decrease number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;      int     answer     =     1  ;      for     (  int     i     =     1  ;     i      <=     r  ;     i  ++  )     {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }      return     answer  ;   }   // function to calculate binomial r.v. probability   float     binomialProbability  (  int     n       int     k       float     p  )   {      return     nCr  (  n       k  )     *     pow  (  p       k  )     *      pow  (  1     -     p       n     -     k  );   }   // Driver code   int     main  ()   {      int     n     =     10  ;      int     k     =     5  ;      float     p     =     1.0     /     3  ;      float     probability     =     binomialProbability  (  n       k       p  );      cout      < <     'Probability of '      < <     k  ;      cout      < <     ' heads when a coin is tossed '      < <     n  ;      cout      < <     ' times where probability of each head is '      < <     p      < <     endl  ;      cout      < <     ' is = '      < <     probability      < <     endl  ;   }   
Java
   // Java program to compute Binomial Probability   import     java.util.*  ;   class   GFG   {      // function to calculate nCr i.e. number of       // ways to choose r out of n objects      static     int     nCr  (  int     n       int     r  )      {      // Since nCr is same as nC(n-r)      // To decrease number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;          int     answer     =     1  ;      for     (  int     i     =     1  ;     i      <=     r  ;     i  ++  )     {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }          return     answer  ;      }          // function to calculate binomial r.v. probability      static     float     binomialProbability  (  int     n       int     k       float     p  )      {      return     nCr  (  n       k  )     *     (  float  )  Math  .  pow  (  p       k  )     *         (  float  )  Math  .  pow  (  1     -     p       n     -     k  );      }          // Driver code      public     static     void     main  (  String  []     args  )      {      int     n     =     10  ;      int     k     =     5  ;      float     p     =     (  float  )  1.0     /     3  ;          float     probability     =     binomialProbability  (  n       k       p  );          System  .  out  .  print  (  'Probability of '     +  k  );      System  .  out  .  print  (  ' heads when a coin is tossed '     +  n  );      System  .  out  .  println  (  ' times where probability of each head is '     +  p  );      System  .  out  .  println  (     ' is = '     +     probability     );      }   }   /* This code is contributed by Mr. Somesh Awasthi */   
Python3
   # Python3 program to compute Binomial    # Probability   # function to calculate nCr i.e.   # number of ways to choose r out   # of n objects   def   nCr  (  n     r  ):   # Since nCr is same as nC(n-r)   # To decrease number of iterations   if   (  r   >   n   /   2  ):   r   =   n   -   r  ;   answer   =   1  ;   for   i   in   range  (  1     r   +   1  ):   answer   *=   (  n   -   r   +   i  );   answer   /=   i  ;   return   answer  ;   # function to calculate binomial r.v.   # probability   def   binomialProbability  (  n     k     p  ):   return   (  nCr  (  n     k  )   *   pow  (  p     k  )   *   pow  (  1   -   p     n   -   k  ));   # Driver code   n   =   10  ;   k   =   5  ;   p   =   1.0   /   3  ;   probability   =   binomialProbability  (  n     k     p  );   print  (  'Probability of'     k     'heads when a coin is tossed'     end   =   ' '  );   print  (  n     'times where probability of each head is'     round  (  p     6  ));   print  (  'is = '     round  (  probability     6  ));   # This code is contributed by mits   
C#
   // C# program to compute Binomial   // Probability.   using     System  ;   class     GFG     {          // function to calculate nCr      // i.e. number of ways to       // choose r out of n objects      static     int     nCr  (  int     n       int     r  )      {          // Since nCr is same as      // nC(n-r) To decrease       // number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;          int     answer     =     1  ;      for     (  int     i     =     1  ;     i      <=     r  ;     i  ++  )      {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }          return     answer  ;      }          // function to calculate binomial      // r.v. probability      static     float     binomialProbability  (      int     n       int     k       float     p  )      {      return     nCr  (  n       k  )     *         (  float  )  Math  .  Pow  (  p       k  )      *     (  float  )  Math  .  Pow  (  1     -     p        n     -     k  );      }          // Driver code      public     static     void     Main  ()      {      int     n     =     10  ;      int     k     =     5  ;      float     p     =     (  float  )  1.0     /     3  ;          float     probability     =         binomialProbability  (  n       k       p  );          Console  .  Write  (  'Probability of '      +     k  );      Console  .  Write  (  ' heads when a coin '      +     'is tossed '     +     n  );      Console  .  Write  (  ' times where '      +     'probability of each head is '      +     p  );      Console  .  Write  (     ' is = '      +     probability     );      }   }   // This code is contributed by nitin mittal.   
JavaScript
    <  script  >   // Javascript program to compute Binomial Probability      // function to calculate nCr i.e. number of       // ways to choose r out of n objects      function     nCr  (  n       r  )      {      // Since nCr is same as nC(n-r)      // To decrease number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;          let     answer     =     1  ;      for     (  let     i     =     1  ;     i      <=     r  ;     i  ++  )     {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }          return     answer  ;      }          // function to calculate binomial r.v. probability      function     binomialProbability  (  n       k       p  )      {      return     nCr  (  n       k  )     *     Math  .  pow  (  p       k  )     *         Math  .  pow  (  1     -     p       n     -     k  );      }       // driver program      let     n     =     10  ;      let     k     =     5  ;      let     p     =     1.0     /     3  ;          let     probability     =     binomialProbability  (  n       k       p  );          document  .  write  (  'Probability of '     +  k  );      document  .  write  (  ' heads when a coin is tossed '     +  n  );      document  .  write  (  ' times where probability of each head is '     +  p  );      document  .  write  (     ' is = '     +     probability     );          // This code is contributed by code_hunt.    <  /script>   
PHP
      // php program to compute Binomial    // Probability   // function to calculate nCr i.e.   // number of ways to choose r out   // of n objects   function   nCr  (  $n     $r  )   {   // Since nCr is same as nC(n-r)   // To decrease number of iterations   if   (  $r   >   $n   /   2  )   $r   =   $n   -   $r  ;   $answer   =   1  ;   for   (  $i   =   1  ;   $i    <=   $r  ;   $i  ++  )   {   $answer   *=   (  $n   -   $r   +   $i  );   $answer   /=   $i  ;   }   return   $answer  ;   }   // function to calculate binomial r.v.   // probability   function   binomialProbability  (  $n     $k     $p  )   {   return   nCr  (  $n     $k  )   *   pow  (  $p     $k  )   *   pow  (  1   -   $p     $n   -   $k  );   }   // Driver code   $n   =   10  ;   $k   =   5  ;   $p   =   1.0   /   3  ;   $probability   =   binomialProbability  (  $n     $k     $p  );   echo   'Probability of '   .   $k  ;   echo   ' heads when a coin is tossed '   .   $n  ;   echo   ' times where probability of '   .   'each head is '   .   $p   ;   echo   ' is = '   .   $probability   ;   // This code is contributed by nitin mittal.   ?>   

الإخراج:  
 

 Probability of 5 heads when a coin is tossed 10 times where probability of each head is 0.333333   
is = 0.136565


 

إنشاء اختبار