Advertisement
roover

Untitled

Sep 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace console1
  8. {
  9.     class Program
  10.     {
  11.         static double[] P;
  12.  
  13.         //ожидаемая вероятность
  14.         static double p = 3;
  15.  
  16.         static int i = 1;
  17.  
  18.         static double mathWait;
  19.         static double dispers;
  20.  
  21.         static double sqrtVariance;
  22.  
  23.         static void Main(string[] args)
  24.         {
  25.             //кол-во сообщений
  26.             int count = 5;
  27.  
  28.             double mathWait = getResult1(count);
  29.  
  30.             if(Math.Floor(mathWait) == count || Math.Ceiling(mathWait) == count)
  31.                 Console.WriteLine("кол-во сообщений примерно равно мат. ожиданию:\n mathWait = " + mathWait + "   count = " + count);
  32.             else if (count > mathWait)
  33.                 Console.WriteLine("кол-во сообщений больше мат. ожидания:\n mathWait = " + mathWait + "   count = " + count);
  34.             else
  35.                 Console.WriteLine("кол-во сообщений меньше мат. ожидания:\n mathWait = " + mathWait + "   count = " + count);
  36.            
  37.             }
  38.  
  39.  
  40.         public static double getResult1(int count)
  41.         {
  42.             int counter = 1;
  43.  
  44.             while (true)
  45.             {
  46.                 for (int i = 0; i < counter; i++)
  47.                 {
  48.                     //мат. ожидание
  49.                     mathWait = i * (Math.Pow(p, i) * (1 - p)) + (i + 1) * (Math.Pow(p, i) * (1 - p)) + (i + 2) * (Math.Pow(p, i) * (1 - p)) + (i + 3) * (Math.Pow(p, i) * (1 - p)) + (i + 4) * (Math.Pow(p, i) * (1 - p));
  50.  
  51.                     //дисперсия
  52.                     dispers = Math.Pow(i, 2) * (Math.Pow(p, i) * (1 - p)) + Math.Pow((i + 1), 2) * (Math.Pow(p, i) * (1 - p)) + Math.Pow((i + 2), 2) * (Math.Pow(p, i) * (1 - p)) + Math.Pow((i + 3), 2) * (Math.Pow(p, i) * (1 - p));
  53.  
  54.                     //средне. квадратическое отклонение
  55.                     sqrtVariance = Math.Sqrt(dispers);
  56.                 }
  57.  
  58.                 counter++;
  59.  
  60.                 if (counter == count+1) break;
  61.  
  62.                
  63.             }
  64.  
  65.             return mathWait;
  66.         }
  67.  
  68.        
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement