Advertisement
Guest User

Untitled

a guest
Nov 28th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.10 KB | None | 0 0
  1. double M = 0.3;
  2.  
  3. double f(double a, int n)
  4. {
  5.     if (n == 0)
  6.         return 1;
  7.  
  8.     double result = _pow(a, n) / fact(n);
  9.  
  10.     double z = 0;
  11.     for (int i = 0; i <= n; i++)
  12.     {
  13.         z+= _pow(a, i) / fact(i);
  14.     }
  15.  
  16.     return result/z;
  17.  
  18. }
  19.  
  20. void count(double[,] A, int [,] B, double [,] C)
  21. {
  22.     for (int i = 0; i < 3; i++)
  23.     {
  24.         for (int j = 0; j < 3; j++)
  25.         {
  26.             for (int n = 0; n < 3; n++)
  27.             {
  28.                 C[i,j] += A[i,n] * f(A[i,n] / M, B[j,n]);
  29.             }
  30.         }
  31.     }
  32. }
  33.  
  34.  
  35. int main()
  36. {
  37.  
  38.     double [,] A = {    {0.4, 0.3, 0.3},
  39.                         {0.3, 0.4, 0.3},
  40.                         {0.4, 0.4, 0.2}};
  41.     int [,] B = {   {2, 1, 1},
  42.                     {3, 1, 0},
  43.                     {2, 2, 0}
  44.                             };
  45.  
  46.     double [,] C = {
  47.                         {0,0,0},
  48.                         {0,0,0},
  49.                         {0,0,0}
  50.                                 };
  51.  
  52.  
  53.  
  54.     count(A, B, C);
  55.  
  56.     for (int i = 0; i < 3; i++)
  57.     {
  58.         for (int j = 0; j < 3; j++)
  59.         {
  60.             print(@"$(C[i,j]) ");
  61.         }
  62.         print("\n");
  63.     }
  64.     return 0;
  65. }
  66.  
  67. double _pow(double p, int q)
  68. {
  69.     double result = 1;
  70.     for (int i = 1; i <= q; i++)
  71.     {
  72.         result *= p;
  73.     }
  74.     return result;
  75. }
  76.  
  77. int fact(int n)
  78. {
  79.     int result = 1;
  80.     for (int i = 2; i <= n; i++)
  81.     {
  82.         result *= i;
  83.     }
  84.     return result;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement