Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- //Constanti
- #define p68 1
- #define p95 1.96
- #define p99 3
- //#define sigmaSstandartnoOtklonenie 0.65
- //#define dopustimaGreshka 0.2
- #define rows 2
- #define columns 5
- #define overAllSum 200
- //#define garancionnaOcenka68
- //#define garancionnaOcenka95
- #define garancionnaOcenka99
- float average = 0;
- float sumOfElements = 0;
- float dx = 0;
- float sigma = 0;
- float gama1 = 0;
- float gama2 = 0;
- float x = 0;
- float gama1s = 0;
- float gamma2s = 0;
- float sigmaS = 0;
- float miu = 0;
- int input[rows+1][columns+1] = {};
- void Average()
- {
- for (int i = 0; i <= columns; i++)
- {
- sumOfElements += input[1][i];
- }
- for (int i = 0; i <= columns; i++)
- {
- average += input[0][i] * input[1][i];
- }
- average /= sumOfElements;
- cout << "Average X: " << average << endl;
- }
- void DispersionAndSigma()
- {
- for (int i = 0; i <= columns; i++)
- {
- dx += pow(input[0][i] - average, 2) * input[1][i];
- }
- dx /= sumOfElements;
- sigma = sqrt(dx);
- cout << "DX: " << dx << " SIGMA: " << sigma << endl;
- }
- void Gamma1()
- {
- for (int i = 0; i <= columns; i++)
- {
- gama1 += pow(input[0][i] - average, 3) * input[1][i];
- }
- gama1 = gama1 / (sumOfElements * pow(sigma, 3));
- cout << "Gama 1: " << gama1 << endl;
- }
- void Gamma2()
- {
- for (int i = 0; i <= columns; i++)
- {
- gama2 += pow(input[0][i] - average, 4) * input[1][i];
- }
- gama2 = gama2 / (sumOfElements * pow(sigma, 4));
- cout << "Gama 2: " << gama2 << endl;
- }
- void PrintTable()
- {
- cout << "Printing the table" << endl;
- cout << "X ";
- int flagFChar = 1;
- auto testNum = input[0][0];
- float testNumFloat = float(input[0][0]);
- int flagFloat = 0;
- if(testNumFloat == testNum)
- {
- flagFloat = 1;
- //cout << "The number is float" << endl;
- }
- for(int i =0; i<rows; i++)
- {
- for(int j = 0; j<columns; j++)
- {
- if(flagFloat && i ==1)
- {
- cout << input[i][j] << " ";
- }
- else
- {
- cout << input[i][j] << " ";
- }
- }
- cout << endl;
- if(flagFChar)
- cout << "F ";
- flagFChar = 0;
- }
- }
- void Gamma1S()
- {
- float rightSide = 6 * (sumOfElements - 1) / ((sumOfElements + 1) * (sumOfElements + 3));
- rightSide = sqrt(rightSide);
- rightSide = rightSide * 3;
- cout <<"The gamma1's right side is: " << rightSide << endl;
- if(gama1<rightSide)
- {
- cout << "Pyrvoto uslovie e izpylneno gamma1s <= " << rightSide << endl;
- }
- else
- {
- cout << "Pyrvoto uslovie ne e izpylneno" << gama1 << ">= " << rightSide << endl;
- }
- }
- void Gamma2S()
- {
- float rightSide = 24*sumOfElements * (sumOfElements - 2) * (sumOfElements - 3) /
- (pow((sumOfElements + 1) ,2)* (sumOfElements + 3)*(sumOfElements+5));
- rightSide = sqrt(rightSide);
- rightSide = rightSide * 3;
- rightSide += 3;
- cout << "The gamma2's right side is: " << rightSide << endl;
- if (gama2 < rightSide)
- {
- cout << "Vtoroto uslovie e izpylneno gamma2s <= " << rightSide << endl;
- }
- else
- {
- cout << "Vtoroto uslovie ne e izpylneno" << gama2 << ">= " << rightSide << endl;
- }
- }
- void SigmaS()
- {
- for (int i = 0; i <= columns; i++)
- {
- sigmaS += pow(input[0][i] - average, 2);
- }
- sigmaS /= sumOfElements;
- cout << "SigmaS is: " << sigmaS << endl;
- }
- void garancionnaVeroqtnost()
- {
- cout << " v garancionna veroqnost miu " << miu << endl;
- float probability = 0;
- float nx = 0;
- float n0 = 0;
- cout << endl;
- #ifdef garancionnaOcenka68
- probability = p68 * miu;
- cout << "Garancionna veroqtnost 68% delta tu: " <<
- probability << endl;
- cout << "Intervalna ocenka: "
- << average << "-" << probability << " = Xs - delta <= X <= Xs + delta = "
- << average << "+" << probability << endl;
- cout << "-> " << average - probability << " <= X <= " << average + probability << endl;
- #ifdef dopustimaGreshka
- nx = (pow(p68, 2) * pow(sigma, 2));
- float underTheLine = pow(p95, 2) * pow(sigma, 2);
- underTheLine /= overAllSum;
- underTheLine = underTheLine + pow(dopustimaGreshka, 2);
- nx = nx / underTheLine;
- cout << "Nx = " << nx << endl;
- n0 = pow(p68, 2) * pow(sigma, 2);
- n0 /= probability;
- cout << "N0 = " << n0 << endl;
- #endif
- #endif
- #ifdef garancionnaOcenka95
- probability = p95 * miu;
- cout << "Garancionna veroqtnost 95% delta tu: " <<
- probability << endl;
- cout << "Intervalna ocenka: "
- << average << "-" << probability << " = Xs - delta <= X <= Xs + delta = "
- << average << "+" << probability << endl;
- cout << "-> " << average - probability << " <= X <= " << average + probability << endl;
- #ifdef dopustimaGreshka
- nx = (pow(p95, 2) * pow(sigma, 2));
- float underTheLine = pow(p95, 2) * pow(sigma, 2);
- underTheLine /= overAllSum;
- underTheLine = underTheLine + pow(dopustimaGreshka, 2);
- nx = nx / underTheLine;
- cout << "Nx = " << nx << endl;
- n0 = pow(p95, 2) * pow(sigma, 2);
- n0 /= probability;
- cout << "N0 = " << n0 << endl;
- #endif
- #endif
- #ifdef garancionnaOcenka99
- probability = p99 * miu;
- cout << "Garancionna veroqtnost 99% delta tu: " <<
- probability << endl;
- cout << "Intervalna ocenka: "
- << average << "-" << probability << " = Xs - delta <= X <= Xs + delta = "
- << average << "+" << probability << endl;
- cout << "-> " << average - probability << " <= X <= " << average + probability << endl;
- #ifdef dopustimaGreshka
- nx = (pow(p99, 2) * pow(sigma, 2));
- float underTheLine = pow(p95, 2) * pow(sigma, 2);
- underTheLine /= overAllSum;
- underTheLine = underTheLine + pow(dopustimaGreshka, 2);
- nx = nx / underTheLine;
- cout << "Nx = " << nx << endl;
- n0 = pow(p99, 2) * pow(dopustimaGreshka, 2);
- n0 /= pow(probability,2);
- cout << "N0 = " << n0 << endl;
- #endif
- #endif
- }
- void MiuKratko()
- {
- #ifdef sigmaSstandartnoOtklonenie
- miu = sigmaSstandartnoOtklonenie / sqrt(sumOfElements);
- cout << "kratko miu u = " << miu << endl;
- #endif
- }
- void Miu()
- {
- #ifdef sigmaSstandartnoOtklonenie
- MiuKratko();
- return;
- #endif
- float tempSigma = sigma;
- float overAllSumTemp = overAllSum;
- if(tempSigma == 0)
- {
- cout << "Sigma e neizvestno, zamenq se sus sigmaS" << endl;
- tempSigma = sigmaS;
- }
- if(overAllSumTemp == 0)
- {
- cout << "N e neizvestno, zamenq se s mu = sigma/sqrt(n)" << endl;
- overAllSumTemp = sigma / (sqrt(sumOfElements));
- }
- miu = (tempSigma / sqrt(sumOfElements));
- miu *= sqrt(1 - (sumOfElements / overAllSumTemp));
- cout << "u = " << miu << endl;
- }
- int main()
- {
- //x = 2 * 5 + 3 * 3 + 4 * 7 + 5 * 0 + 6 * 2;
- //x = x / 17;
- /*input[0][0] = 2;
- input[0][1] = 3;
- input[0][2] = 4;
- input[0][3] = 5;
- input[0][4] = 6;
- input[1][0] = 5;
- input[1][1] = 3;
- input[1][2] = 7;
- input[1][3] = 3;
- input[1][4] = 2;*/
- /*input[0][0] = 7.7;
- input[0][1] = 8.1;
- input[0][2] = 8.5;
- input[0][3] = 9.4;
- input[0][4] = 9.6;
- input[0][5] = 10.2;
- input[1][0] = 3;
- input[1][1] = 4;
- input[1][2] = 4;
- input[1][3] = 3;
- input[1][4] = 4;
- input[1][5] = 2;*/
- input[0][0] = 2;
- input[0][1] = 3;
- input[0][2] = 4;
- input[0][3] = 5;
- input[0][4] = 6;
- input[1][0] = 5;
- input[1][1] = 3;
- input[1][2] = 7;
- input[1][3] = 0;
- input[1][4] = 2;
- PrintTable();
- Average();
- DispersionAndSigma();
- Gamma1();
- Gamma2();
- Gamma1S();
- Gamma2S();
- SigmaS();
- Miu();
- garancionnaVeroqtnost();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement