# Math controlno - statistics - added some things

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