Advertisement
193030

Math kontrolno - statistics

Dec 8th, 2020
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. //Constanti
  7. #define p68 1
  8. #define p95 1.96
  9. #define p99 3
  10.  
  11.  
  12. //#define sigmaSstandartnoOtklonenie 0.65
  13. //#define dopustimaGreshka 0.2
  14. #define rows 2
  15. #define columns 5
  16. #define overAllSum 200
  17. //#define garancionnaOcenka68
  18. //#define garancionnaOcenka95
  19. #define garancionnaOcenka99
  20.  
  21. float average = 0;
  22. float sumOfElements = 0;
  23. float dx = 0;
  24. float sigma = 0;
  25. float gama1 = 0;
  26. float gama2 = 0;
  27. float x = 0;
  28. float gama1s = 0;
  29. float gamma2s = 0;
  30. float sigmaS = 0;
  31. float miu = 0;
  32. int input[rows+1][columns+1] = {};
  33.  
  34.  
  35.  
  36. void Average()
  37. {
  38.     for (int i = 0; i <= columns; i++)
  39.     {
  40.         sumOfElements += input[1][i];
  41.     }
  42.     for (int i = 0; i <= columns; i++)
  43.     {
  44.         average += input[0][i] * input[1][i];
  45.     }
  46.     average /= sumOfElements;
  47.     cout << "Average X: " << average << endl;
  48. }
  49.  
  50. void DispersionAndSigma()
  51. {
  52.     for (int i = 0; i <= columns; i++)
  53.     {
  54.         dx += pow(input[0][i] - average, 2) * input[1][i];
  55.     }
  56.     dx /= sumOfElements;
  57.     sigma = sqrt(dx);
  58.     cout << "DX: " << dx << " SIGMA: " << sigma << endl;
  59. }
  60.  
  61. void Gamma1()
  62. {
  63.     for (int i = 0; i <= columns; i++)
  64.     {
  65.         gama1 += pow(input[0][i] - average, 3) * input[1][i];
  66.     }
  67.     gama1 = gama1 / (sumOfElements * pow(sigma, 3));
  68.     cout << "Gama 1: " << gama1 << endl;
  69.  
  70.  
  71. }
  72.  
  73. void Gamma2()
  74. {
  75.     for (int i = 0; i <= columns; i++)
  76.     {
  77.         gama2 += pow(input[0][i] - average, 4) * input[1][i];
  78.     }
  79.     gama2 = gama2 / (sumOfElements * pow(sigma, 4));
  80.     cout << "Gama 2: " << gama2 << endl;
  81. }
  82.  
  83. void PrintTable()
  84. {
  85.     cout << "Printing the table" << endl;
  86.     cout << "X ";
  87.     int flagFChar = 1;
  88.     auto testNum = input[0][0];
  89.     float testNumFloat = float(input[0][0]);
  90.     int flagFloat = 0;
  91.     if(testNumFloat == testNum)
  92.     {
  93.         flagFloat = 1;
  94.         //cout << "The number is float" << endl;
  95.     }
  96.     for(int i =0; i<rows; i++)
  97.     {
  98.         for(int j = 0; j<columns; j++)
  99.         {
  100.             if(flagFloat && i ==1)
  101.             {
  102.                 cout << input[i][j] << "   ";
  103.  
  104.             }
  105.             else
  106.             {
  107.                 cout << input[i][j] << " ";
  108.  
  109.             }
  110.         }
  111.         cout << endl;
  112.         if(flagFChar)
  113.             cout << "F ";
  114.         flagFChar = 0;
  115.     }
  116. }
  117.  
  118. void Gamma1S()
  119. {
  120.     float rightSide = 6 * (sumOfElements - 1) / ((sumOfElements + 1) * (sumOfElements + 3));
  121.     rightSide = sqrt(rightSide);
  122.     rightSide = rightSide * 3;
  123.     cout <<"The gamma1's right side is: " << rightSide << endl;
  124.  
  125.     if(gama1<rightSide)
  126.     {
  127.         cout << "Pyrvoto uslovie  e izpylneno gamma1s <= " << rightSide << endl;
  128.     }
  129.     else
  130.     {
  131.         cout << "Pyrvoto uslovie ne e izpylneno" << gama1 << ">= " << rightSide << endl;
  132.     }
  133.    
  134. }
  135. void Gamma2S()
  136. {
  137.     float rightSide = 24*sumOfElements * (sumOfElements - 2) * (sumOfElements - 3) /
  138.         (pow((sumOfElements + 1) ,2)* (sumOfElements + 3)*(sumOfElements+5));
  139.     rightSide = sqrt(rightSide);
  140.     rightSide = rightSide * 3;
  141.     rightSide += 3;
  142.  
  143.     cout << "The gamma2's right side is: " << rightSide << endl;
  144.  
  145.     if (gama2 < rightSide)
  146.     {
  147.         cout << "Vtoroto uslovie  e izpylneno gamma2s <= " << rightSide << endl;
  148.     }
  149.     else
  150.     {
  151.         cout << "Vtoroto uslovie ne e izpylneno" << gama2 << ">= " << rightSide << endl;
  152.     }
  153.  
  154. }
  155.  
  156. void SigmaS()
  157. {
  158.     for (int i = 0; i <= columns; i++)
  159.     {
  160.         sigmaS += pow(input[0][i] - average, 2);
  161.     }
  162.     sigmaS /= sumOfElements;
  163.     cout << "SigmaS is: " << sigmaS << endl;
  164. }
  165.  
  166. void garancionnaVeroqtnost()
  167. {
  168.     cout << " v garancionna veroqnost miu " << miu << endl;
  169.     float probability = 0;
  170.     float nx = 0;
  171.     float n0 = 0;
  172.     cout << endl;
  173.  
  174. #ifdef garancionnaOcenka68
  175.     probability = p68 * miu;
  176.     cout << "Garancionna veroqtnost 68% delta tu: " <<
  177.         probability << endl;
  178.     cout << "Intervalna ocenka: "
  179.         << average << "-" << probability << " = Xs - delta <= X <= Xs + delta = "
  180.         << average << "+" << probability << endl;
  181.     cout << "-> " << average - probability << " <= X <= " << average + probability << endl;
  182. #ifdef dopustimaGreshka
  183.     nx = (pow(p68, 2) * pow(sigma, 2));
  184.     float underTheLine = pow(p95, 2) * pow(sigma, 2);
  185.     underTheLine /= overAllSum;
  186.     underTheLine = underTheLine + pow(dopustimaGreshka, 2);
  187.     nx = nx / underTheLine;
  188.  
  189.     cout << "Nx = " << nx << endl;
  190.  
  191.     n0 = pow(p68, 2) * pow(sigma, 2);
  192.     n0 /= probability;
  193.     cout << "N0 = " << n0 << endl;
  194.  
  195. #endif
  196. #endif
  197. #ifdef garancionnaOcenka95
  198.     probability = p95 * miu;
  199.     cout << "Garancionna veroqtnost 95% delta tu: " <<
  200.         probability << endl;
  201.     cout << "Intervalna ocenka: "
  202.         << average << "-" << probability << " = Xs - delta <= X <= Xs + delta = "
  203.         << average << "+" << probability << endl;
  204.     cout << "-> " << average - probability << " <= X <= " << average + probability << endl;
  205.  
  206. #ifdef dopustimaGreshka
  207.     nx = (pow(p95, 2) * pow(sigma, 2));
  208.     float underTheLine = pow(p95, 2) * pow(sigma, 2);
  209.     underTheLine /= overAllSum;
  210.     underTheLine = underTheLine + pow(dopustimaGreshka, 2);
  211.     nx = nx / underTheLine;
  212.  
  213.     cout << "Nx = " << nx << endl;
  214.  
  215.  
  216.     n0 = pow(p95, 2) * pow(sigma, 2);
  217.     n0 /= probability;
  218.     cout << "N0 = " << n0 << endl;
  219.  
  220.  
  221. #endif
  222. #endif
  223.  
  224. #ifdef garancionnaOcenka99
  225.     probability = p99 * miu;
  226.     cout << "Garancionna veroqtnost 99% delta tu: " <<
  227.         probability << endl;
  228.     cout << "Intervalna ocenka: "
  229.         << average << "-" << probability << " = Xs - delta <= X <= Xs + delta = "
  230.         << average << "+" << probability << endl;
  231.     cout << "-> " << average - probability << " <= X <= " << average + probability << endl;
  232. #ifdef dopustimaGreshka
  233.     nx = (pow(p99, 2) * pow(sigma, 2));
  234.     float underTheLine = pow(p95, 2) * pow(sigma, 2);
  235.     underTheLine /= overAllSum;
  236.     underTheLine = underTheLine + pow(dopustimaGreshka, 2);
  237.     nx = nx / underTheLine;
  238.  
  239.  
  240.    
  241.     cout << "Nx = " << nx << endl;
  242.  
  243.     n0 = pow(p99, 2) * pow(dopustimaGreshka, 2);
  244.     n0 /= pow(probability,2);
  245.     cout << "N0 = " << n0 << endl;
  246.  
  247. #endif
  248. #endif 
  249. }
  250. void MiuKratko()
  251. {
  252. #ifdef sigmaSstandartnoOtklonenie
  253.     miu = sigmaSstandartnoOtklonenie / sqrt(sumOfElements);
  254.     cout << "kratko miu u = " << miu << endl;
  255. #endif
  256.    
  257. }
  258. void Miu()
  259. {
  260. #ifdef sigmaSstandartnoOtklonenie
  261.     MiuKratko();
  262.     return;
  263. #endif
  264.     float tempSigma = sigma;
  265.     float overAllSumTemp = overAllSum;
  266.  
  267.     if(tempSigma == 0)
  268.     {
  269.         cout << "Sigma e neizvestno, zamenq se sus sigmaS" << endl;
  270.         tempSigma = sigmaS;
  271.     }
  272.     if(overAllSumTemp == 0)
  273.     {
  274.         cout << "N e neizvestno, zamenq se s mu = sigma/sqrt(n)" << endl;
  275.         overAllSumTemp = sigma / (sqrt(sumOfElements));
  276.     }
  277.  
  278.    
  279.     miu = (tempSigma / sqrt(sumOfElements));
  280.     miu *= sqrt(1 - (sumOfElements / overAllSumTemp));
  281.        
  282.     cout << "u = " << miu << endl;
  283.    
  284.  
  285.  
  286.    
  287. }
  288.  
  289.  
  290. int main()
  291. {
  292.    
  293.    
  294.     //x = 2 * 5 + 3 * 3 + 4 * 7 + 5 * 0 + 6 * 2;
  295.     //x = x / 17;
  296.     /*input[0][0] = 2;
  297.     input[0][1] = 3;
  298.     input[0][2] = 4;
  299.     input[0][3] = 5;
  300.     input[0][4] = 6;
  301.  
  302.     input[1][0] = 5;
  303.     input[1][1] = 3;
  304.     input[1][2] = 7;
  305.     input[1][3] = 3;
  306.     input[1][4] = 2;*/
  307.  
  308.     /*input[0][0] = 7.7;
  309.     input[0][1] = 8.1;
  310.     input[0][2] = 8.5;
  311.     input[0][3] = 9.4;
  312.     input[0][4] = 9.6;
  313.     input[0][5] = 10.2;
  314.  
  315.     input[1][0] = 3;
  316.     input[1][1] = 4;
  317.     input[1][2] = 4;
  318.     input[1][3] = 3;
  319.     input[1][4] = 4;
  320.     input[1][5] = 2;*/
  321.  
  322.     input[0][0] = 2;
  323.     input[0][1] = 3;
  324.     input[0][2] = 4;
  325.     input[0][3] = 5;
  326.     input[0][4] = 6;
  327.  
  328.     input[1][0] = 5;
  329.     input[1][1] = 3;
  330.     input[1][2] = 7;
  331.     input[1][3] = 0;
  332.     input[1][4] = 2;
  333.  
  334.     PrintTable();
  335.     Average();
  336.     DispersionAndSigma();
  337.     Gamma1();
  338.     Gamma2();
  339.     Gamma1S();
  340.     Gamma2S();
  341.     SigmaS();
  342.     Miu();
  343.     garancionnaVeroqtnost();
  344.  
  345.  
  346.  
  347.  
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement